diff --git a/Cargo.lock b/Cargo.lock index 280322d9..fc12239a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,22 +12,13 @@ dependencies = [ "regex", ] -[[package]] -name = "addr2line" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e61f2b7f93d2c7d2b08263acaa4a363b3e276806c68af6134c44f523bf1aacd" -dependencies = [ - "gimli 0.25.0", -] - [[package]] name = "addr2line" version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" dependencies = [ - "gimli 0.26.1", + "gimli", ] [[package]] @@ -412,9 +403,9 @@ dependencies = [ [[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" @@ -422,7 +413,7 @@ version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f" dependencies = [ - "addr2line 0.17.0", + "addr2line", "cc", "cfg-if 1.0.0", "libc", @@ -491,14 +482,15 @@ dependencies = [ [[package]] name = "beefy-gadget" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "beefy-primitives", "fnv", - "futures 0.3.19", + "futures 0.3.21", "log", "parity-scale-codec", "parking_lot 0.11.2", + "sc-chain-spec", "sc-client-api", "sc-keystore", "sc-network", @@ -508,8 +500,8 @@ dependencies = [ "sp-application-crypto", "sp-arithmetic", "sp-blockchain", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-keystore 0.10.0", "sp-runtime", "substrate-prometheus-endpoint", "thiserror", @@ -519,40 +511,44 @@ dependencies = [ [[package]] name = "beefy-gadget-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "beefy-gadget", "beefy-primitives", - "futures 0.3.19", + "derive_more", + "futures 0.3.21", "jsonrpc-core 18.0.0", "jsonrpc-core-client 18.0.0", "jsonrpc-derive 18.0.0", "jsonrpc-pubsub 18.0.0", "log", "parity-scale-codec", + "parking_lot 0.11.2", "sc-rpc", + "sc-utils", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", + "thiserror", ] [[package]] name = "beefy-merkle-tree" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" [[package]] name = "beefy-primitives" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", "scale-info", "sp-api", "sp-application-crypto", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] @@ -687,6 +683,15 @@ dependencies = [ "generic-array 0.14.5", ] +[[package]] +name = "block-buffer" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +dependencies = [ + "generic-array 0.14.5", +] + [[package]] name = "block-padding" version = "0.1.5" @@ -726,9 +731,9 @@ dependencies = [ [[package]] name = "bounded-vec" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afdd1dffefe5fc66262a524b91087c43b16e478b2e3dc49eb11b0e2fd6b6ec90" +checksum = "b47cca82fca99417fe405f09d93bb8fff90bdd03d13c631f18096ee123b4281c" dependencies = [ "thiserror", ] @@ -736,35 +741,35 @@ dependencies = [ [[package]] name = "bp-header-chain" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "finality-grandpa", "frame-support", "parity-scale-codec", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-finality-grandpa", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "bp-message-dispatch" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bp-runtime", "frame-support", "parity-scale-codec", "scale-info", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "bp-messages" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bitvec", "bp-runtime", @@ -774,13 +779,13 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "bp-polkadot-core" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bp-messages", "bp-runtime", @@ -789,31 +794,16 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "sp-version", ] -[[package]] -name = "bp-rialto" -version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" -dependencies = [ - "bp-messages", - "bp-runtime", - "frame-support", - "frame-system", - "sp-api", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", -] - [[package]] name = "bp-rococo" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bp-messages", "bp-polkadot-core", @@ -823,32 +813,32 @@ dependencies = [ "smallvec 1.8.0", "sp-api", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "sp-version", ] [[package]] name = "bp-runtime" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "frame-support", "hash-db", "num-traits", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", + "sp-std 4.0.0", + "sp-trie 4.0.0", ] [[package]] name = "bp-test-utils" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bp-header-chain", "ed25519-dalek", @@ -857,13 +847,13 @@ dependencies = [ "sp-application-crypto", "sp-finality-grandpa", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "bp-wococo" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bp-messages", "bp-polkadot-core", @@ -872,13 +862,13 @@ dependencies = [ "parity-scale-codec", "sp-api", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "bridge-runtime-common" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bp-message-dispatch", "bp-messages", @@ -891,11 +881,11 @@ dependencies = [ "pallet-transaction-payment", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", + "sp-std 4.0.0", + "sp-trie 4.0.0", ] [[package]] @@ -1004,13 +994,13 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba2ae6de944143141f6155a473a6b02f66c7c3f9f47316f802f80204ebfe6e12" +checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" dependencies = [ "camino", "cargo-platform", - "semver 1.0.4", + "semver 1.0.5", "serde", "serde_json", ] @@ -1204,9 +1194,9 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "core-foundation" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" dependencies = [ "core-foundation-sys", "libc", @@ -1247,24 +1237,24 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.78.0" +version = "0.80.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc0cb7df82c8cf8f2e6a8dd394a0932a71369c160cc9b027dca414fced242513" +checksum = "9516ba6b2ba47b4cbf63b713f75b432fafa0a0e0464ec8381ec76e6efe931ab3" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.78.0" +version = "0.80.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe4463c15fa42eee909e61e5eac4866b7c6d22d0d8c621e57a0c5380753bfa8c" +checksum = "489e5d0081f7edff6be12d71282a8bf387b5df64d5592454b75d662397f2d642" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", "cranelift-entity", - "gimli 0.25.0", + "gimli", "log", "regalloc", "smallvec 1.8.0", @@ -1273,34 +1263,33 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.78.0" +version = "0.80.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793f6a94a053a55404ea16e1700202a88101672b8cd6b4df63e13cde950852bf" +checksum = "d36ee1140371bb0f69100e734b30400157a4adf7b86148dee8b0a438763ead48" dependencies = [ "cranelift-codegen-shared", - "cranelift-entity", ] [[package]] name = "cranelift-codegen-shared" -version = "0.78.0" +version = "0.80.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44aa1846df275bce5eb30379d65964c7afc63c05a117076e62a119c25fe174be" +checksum = "981da52d8f746af1feb96290c83977ff8d41071a7499e991d8abae0d4869f564" [[package]] name = "cranelift-entity" -version = "0.78.0" +version = "0.80.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3a45d8d6318bf8fc518154d9298eab2a8154ec068a8885ff113f6db8d69bb3a" +checksum = "a2906740053dd3bcf95ce53df0fd9b5649c68ae4bd9adada92b406f059eae461" dependencies = [ "serde", ] [[package]] name = "cranelift-frontend" -version = "0.78.0" +version = "0.80.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e07339bd461766deb7605169de039e01954768ff730fa1254e149001884a8525" +checksum = "b7cb156de1097f567d46bf57a0cd720a72c3e15e1a2bd8b1041ba2fc894471b7" dependencies = [ "cranelift-codegen", "log", @@ -1310,9 +1299,9 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.78.0" +version = "0.80.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e2fca76ff57e0532936a71e3fc267eae6a19a86656716479c66e7f912e3d7b" +checksum = "166028ca0343a6ee7bddac0e70084e142b23f99c701bd6f6ea9123afac1a7a46" dependencies = [ "cranelift-codegen", "libc", @@ -1321,9 +1310,9 @@ dependencies = [ [[package]] name = "cranelift-wasm" -version = "0.78.0" +version = "0.80.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f46fec547a1f8a32c54ea61c28be4f4ad234ad95342b718a9a9adcaadb0c778" +checksum = "5012a1cde0c8b3898770b711490d803018ae9bec2d60674ba0e5b2058a874f80" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -1337,9 +1326,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.3.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2209c310e29876f7f0b2721e7e26b84aff178aa3da5d091f9bfbf47669e60e3" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ "cfg-if 1.0.0", ] @@ -1367,9 +1356,9 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.6" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97242a70df9b89a65d0b6df3c4bf5b9ce03c5b7309019777fbde37e7537f8762" +checksum = "c00d6d2ea26e8b151d99093005cb442fb9a37aeaca582a03ec70946f49ab5ed9" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -1380,9 +1369,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120" +checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6" dependencies = [ "cfg-if 1.0.0", "lazy_static", @@ -1394,6 +1383,16 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-common" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" +dependencies = [ + "generic-array 0.14.5", + "typenum 1.15.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crypto-mac" version = "0.8.0" @@ -1456,7 +1455,7 @@ dependencies = [ [[package]] name = "cumulus-client-cli" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "sc-cli", "sc-service", @@ -1466,12 +1465,13 @@ dependencies = [ [[package]] name = "cumulus-client-collator" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "cumulus-client-consensus-common", "cumulus-client-network", "cumulus-primitives-core", - "futures 0.3.19", + "cumulus-relay-chain-interface", + "futures 0.3.21", "parity-scale-codec", "parking_lot 0.10.2", "polkadot-node-primitives", @@ -1481,7 +1481,7 @@ dependencies = [ "sc-client-api", "sp-api", "sp-consensus", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", "tracing", ] @@ -1489,11 +1489,12 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-common" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "async-trait", + "cumulus-relay-chain-interface", "dyn-clone", - "futures 0.3.19", + "futures 0.3.21", "parity-scale-codec", "polkadot-primitives", "sc-client-api", @@ -1502,28 +1503,28 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-runtime", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-trie 4.0.0", "tracing", ] [[package]] name = "cumulus-client-consensus-relay-chain" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "async-trait", "cumulus-client-consensus-common", "cumulus-primitives-core", - "futures 0.3.19", + "cumulus-relay-chain-interface", + "futures 0.3.21", "parking_lot 0.10.2", - "polkadot-client", "sc-client-api", "sc-consensus", "sp-api", "sp-block-builder", "sp-blockchain", "sp-consensus", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", "sp-runtime", "substrate-prometheus-endpoint", @@ -1533,14 +1534,15 @@ dependencies = [ [[package]] name = "cumulus-client-network" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ + "async-trait", + "cumulus-relay-chain-interface", "derive_more", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "parity-scale-codec", - "parking_lot 0.10.2", - "polkadot-client", + "parking_lot 0.11.2", "polkadot-node-primitives", "polkadot-parachain", "polkadot-primitives", @@ -1548,25 +1550,27 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-consensus", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", + "sp-state-machine 0.10.0", "tracing", ] [[package]] name = "cumulus-client-pov-recovery" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "cumulus-primitives-core", - "futures 0.3.19", - "futures-timer 3.0.2", + "cumulus-relay-chain-interface", + "futures 0.3.21", + "futures-timer", "parity-scale-codec", "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-overseer", "polkadot-primitives", - "rand 0.8.4", + "rand 0.8.5", "sc-client-api", "sc-consensus", "sp-api", @@ -1579,17 +1583,17 @@ dependencies = [ [[package]] name = "cumulus-client-service" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "cumulus-client-collator", "cumulus-client-consensus-common", "cumulus-client-pov-recovery", "cumulus-primitives-core", + "cumulus-relay-chain-interface", "parity-scale-codec", "parking_lot 0.10.2", "polkadot-overseer", "polkadot-primitives", - "polkadot-service", "sc-chain-spec", "sc-client-api", "sc-consensus", @@ -1600,7 +1604,7 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-consensus", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", "tracing", ] @@ -1608,7 +1612,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-dmp-queue" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -1616,9 +1620,9 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", "xcm-executor", ] @@ -1626,7 +1630,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-parachain-system" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "cumulus-pallet-parachain-system-proc-macro", "cumulus-primitives-core", @@ -1634,20 +1638,21 @@ dependencies = [ "environmental", "frame-support", "frame-system", + "impl-trait-for-tuples", "log", "pallet-balances", "parity-scale-codec", "polkadot-parachain", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-externalities 0.10.0", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", + "sp-std 4.0.0", + "sp-trie 4.0.0", "sp-version", "xcm", ] @@ -1655,9 +1660,9 @@ dependencies = [ [[package]] name = "cumulus-pallet-parachain-system-proc-macro" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -1666,7 +1671,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-xcm" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -1674,16 +1679,16 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", ] [[package]] name = "cumulus-pallet-xcmp-queue" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -1693,7 +1698,7 @@ dependencies = [ "rand_chacha 0.3.1", "scale-info", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", "xcm-executor", ] @@ -1701,57 +1706,57 @@ dependencies = [ [[package]] name = "cumulus-primitives-core" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "frame-support", - "impl-trait-for-tuples", "parity-scale-codec", "polkadot-core-primitives", "polkadot-parachain", "polkadot-primitives", "sp-api", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", + "sp-trie 4.0.0", ] [[package]] name = "cumulus-primitives-parachain-inherent" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "async-trait", "cumulus-primitives-core", + "cumulus-relay-chain-interface", "cumulus-test-relay-sproof-builder", "parity-scale-codec", - "polkadot-client", "sc-client-api", "scale-info", "sp-api", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", + "sp-std 4.0.0", + "sp-storage 4.0.0", + "sp-trie 4.0.0", "tracing", ] [[package]] name = "cumulus-primitives-timestamp" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "cumulus-primitives-core", "sp-inherents", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "sp-timestamp", ] [[package]] name = "cumulus-primitives-utility" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -1760,22 +1765,71 @@ dependencies = [ "polkadot-parachain", "polkadot-primitives", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", + "sp-trie 4.0.0", "xcm", ] +[[package]] +name = "cumulus-relay-chain-interface" +version = "0.1.0" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" +dependencies = [ + "async-trait", + "cumulus-primitives-core", + "derive_more", + "futures 0.3.21", + "parking_lot 0.11.2", + "polkadot-overseer", + "sc-client-api", + "sc-service", + "sp-api", + "sp-blockchain", + "sp-core 4.1.0-dev", + "sp-runtime", + "sp-state-machine 0.10.0", + "thiserror", +] + +[[package]] +name = "cumulus-relay-chain-local" +version = "0.1.0" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" +dependencies = [ + "async-trait", + "cumulus-primitives-core", + "cumulus-relay-chain-interface", + "futures 0.3.21", + "futures-timer", + "parking_lot 0.11.2", + "polkadot-client", + "polkadot-service", + "sc-client-api", + "sc-consensus-babe", + "sc-network", + "sc-service", + "sc-telemetry", + "sc-tracing", + "sp-api", + "sp-blockchain", + "sp-consensus", + "sp-core 4.1.0-dev", + "sp-runtime", + "sp-state-machine 0.10.0", + "tracing", +] + [[package]] name = "cumulus-test-relay-sproof-builder" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "cumulus-primitives-core", "parity-scale-codec", "polkadot-primitives", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", + "sp-std 4.0.0", ] [[package]] @@ -1928,6 +1982,16 @@ dependencies = [ "generic-array 0.14.5", ] +[[package]] +name = "digest" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +dependencies = [ + "block-buffer 0.10.2", + "crypto-common", +] + [[package]] name = "directories" version = "4.0.1" @@ -2116,19 +2180,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.9.0" @@ -2136,7 +2187,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3" dependencies = [ "atty", - "humantime 2.1.0", + "humantime", "log", "regex", "termcolor", @@ -2231,7 +2282,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e43f2f1833d64e33f15592464d6fdd70f349dda7b1a53088eb83cd94014008c5" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", ] [[package]] @@ -2304,11 +2355,11 @@ dependencies = [ [[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", "log", ] @@ -2319,8 +2370,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8ac3ff5224ef91f3c97e03eb1de2db82743427e91aaa5ac635f454f0b164f5a" dependencies = [ "either", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "log", "num-traits", "parity-scale-codec", @@ -2335,7 +2386,7 @@ 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", ] @@ -2365,6 +2416,19 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "flume" +version = "0.10.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b279436a715a9de95dcd26b151db590a71961cc06e54918b24fe0dd5b7d3fc4" +dependencies = [ + "futures-core", + "futures-sink", + "nanorand", + "pin-project 1.0.10", + "spin 0.9.2", +] + [[package]] name = "fnv" version = "1.0.7" @@ -2374,7 +2438,7 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "fork-tree" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", ] @@ -2392,7 +2456,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", @@ -2402,17 +2466,18 @@ dependencies = [ "paste", "scale-info", "sp-api", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-application-crypto", + "sp-io 4.0.0", "sp-runtime", - "sp-runtime-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-storage 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-runtime-interface 4.1.0-dev", + "sp-std 4.0.0", + "sp-storage 4.0.0", ] [[package]] name = "frame-benchmarking-cli" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "Inflector", "chrono", @@ -2427,18 +2492,18 @@ dependencies = [ "sc-executor", "sc-service", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-externalities 0.10.0", + "sp-keystore 0.10.0", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", "structopt", ] [[package]] name = "frame-election-provider-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", @@ -2446,23 +2511,23 @@ dependencies = [ "scale-info", "sp-arithmetic", "sp-npos-elections", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "frame-executive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-tracing 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", + "sp-tracing 4.0.0", ] [[package]] @@ -2480,7 +2545,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "bitflags", "frame-metadata", @@ -2494,22 +2559,22 @@ dependencies = [ "serde", "smallvec 1.8.0", "sp-arithmetic", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-core-hashing-proc-macro", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", "sp-staking", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-tracing 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", + "sp-std 4.0.0", + "sp-tracing 4.0.0", "tt-call", ] [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "Inflector", "frame-support-procedural-tools", @@ -2521,10 +2586,10 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support-procedural-tools-derive", - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -2533,7 +2598,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "proc-macro2", "quote", @@ -2543,39 +2608,39 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "log", "parity-scale-codec", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "sp-version", ] [[package]] name = "frame-system-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "frame-system-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", "sp-api", @@ -2584,12 +2649,12 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "sp-api", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] @@ -2650,9 +2715,9 @@ checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" [[package]] name = "futures" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28560757fe2bb34e79f907794bb6b22ae8b0e5c669b638a1132f2592b19035b4" +checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" dependencies = [ "futures-channel", "futures-core", @@ -2665,9 +2730,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b" +checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" dependencies = [ "futures-core", "futures-sink", @@ -2675,15 +2740,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" [[package]] name = "futures-executor" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29d6d2ff5bb10fb95c85b8ce46538a2e5f5e7fdc755623a7d4529ab8a4ed9d2a" +checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" dependencies = [ "futures-core", "futures-task", @@ -2693,9 +2758,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2" +checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" [[package]] name = "futures-lite" @@ -2714,9 +2779,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dbd947adfffb0efc70599b3ddcf7b5597bb5fa9e245eb99f62b3a5f7bb8bd3c" +checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" dependencies = [ "proc-macro2", "quote", @@ -2736,21 +2801,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3055baccb68d74ff6480350f8d6eb8fcfa3aa11bdc1a1ae3afdd0514617d508" +checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" [[package]] name = "futures-task" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72" - -[[package]] -name = "futures-timer" -version = "2.0.2" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1de7508b218029b0f01662ed8f61b1c964b3ae99d6f25462d0f55a595109df6" +checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" [[package]] name = "futures-timer" @@ -2760,9 +2819,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164" +checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" dependencies = [ "futures 0.1.31", "futures-channel", @@ -2834,21 +2893,15 @@ dependencies = [ [[package]] name = "gimli" -version = "0.25.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" +checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" dependencies = [ "fallible-iterator", "indexmap 1.8.0", "stable_deref_trait", ] -[[package]] -name = "gimli" -version = "0.26.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" - [[package]] name = "glob" version = "0.3.0" @@ -2889,11 +2942,11 @@ dependencies = [ "getrandom 0.2.4", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", + "sp-keystore 0.10.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] @@ -2962,6 +3015,15 @@ dependencies = [ "ahash 0.7.6", ] +[[package]] +name = "hashbrown" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" +dependencies = [ + "ahash 0.7.6", +] + [[package]] name = "heck" version = "0.3.3" @@ -3064,9 +3126,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" +checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" [[package]] name = "httpdate" @@ -3074,15 +3136,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" -[[package]] -name = "humantime" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" -dependencies = [ - "quick-error 1.2.3", -] - [[package]] name = "humantime" version = "2.1.0" @@ -3091,9 +3144,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.16" +version = "0.14.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7ec3e62bdc98a2f0393a5048e4c30ef659440ea6e0e572965103e72bd836f55" +checksum = "043f0e083e9901b6cc658a77d1eb86f4fc650bbb977a4337dd63192826aa85dd" dependencies = [ "bytes 1.1.0", "futures-channel", @@ -3104,7 +3157,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 0.4.8", + "itoa 1.0.1", "pin-project-lite 0.2.8", "socket2 0.4.4", "tokio", @@ -3180,7 +3233,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae8ab7f67bad3240049cb24fb9cb0b4c2c6af4c245840917fbbdededeee91179" dependencies = [ "async-io", - "futures 0.3.19", + "futures 0.3.21", "futures-lite", "if-addrs", "ipnet", @@ -3218,9 +3271,9 @@ dependencies = [ [[package]] name = "impl-trait-for-tuples" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5dacb10c5b3bb92d46ba347505a9041e676bb20ad220101326bffb0c93031ee" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" dependencies = [ "proc-macro2", "quote", @@ -3272,23 +3325,12 @@ dependencies = [ "num-traits", ] -[[package]] -name = "intervalier" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64fa110ec7b8f493f416eed552740d10e7030ad5f63b2308f82c9608ec2df275" -dependencies = [ - "futures 0.3.19", - "futures-timer 2.0.2", -] - [[package]] name = "io-lifetimes" -version = "0.3.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "278e90d6f8a6c76a8334b336e306efa3c5f2b604048cbfd486d6f49878e3af14" +checksum = "f6ef6787e7f0faedc040f95716bdd0e62bcfcf4ba93da053b62dea2691c13864" dependencies = [ - "rustc_version 0.4.0", "winapi 0.3.9", ] @@ -3387,7 +3429,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2b99d4207e2a04fb4581746903c2bb7eb376f88de9c699d0f3e10feeac0cd3a" dependencies = [ "derive_more", - "futures 0.3.19", + "futures 0.3.21", "jsonrpc-core 18.0.0", "jsonrpc-pubsub 18.0.0", "log", @@ -3428,7 +3470,7 @@ version = "18.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14f7f76aef2d054868398427f6c54943cf3d1caa9a7ec7d0c38d69df97a965eb" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "futures-executor", "futures-util", "log", @@ -3452,7 +3494,7 @@ version = "18.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b51da17abecbdab3e3d4f26b01c5ec075e88d3abe3ab3b05dc9aa69392764ec0" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "jsonrpc-client-transports 18.0.0", ] @@ -3486,7 +3528,7 @@ version = "18.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1dea6e07251d9ce6a552abfb5d7ad6bc290a4596c8dcc3d795fae2bbdc1f3ff" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "hyper", "jsonrpc-core 18.0.0", "jsonrpc-server-utils", @@ -3502,7 +3544,7 @@ version = "18.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "382bb0206323ca7cda3dcd7e245cea86d37d02457a02a975e3378fb149a48845" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "jsonrpc-core 18.0.0", "jsonrpc-server-utils", "log", @@ -3543,7 +3585,7 @@ version = "18.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240f87695e6c6f62fb37f05c02c04953cf68d6408b8c1c89de85c7a0125b1011" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "jsonrpc-core 18.0.0", "lazy_static", "log", @@ -3559,7 +3601,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa4fdea130485b572c39a460d50888beb00afb3e35de23ccd7fad8ff19f0e0d4" dependencies = [ "bytes 1.1.0", - "futures 0.3.19", + "futures 0.3.21", "globset", "jsonrpc-core 18.0.0", "lazy_static", @@ -3576,7 +3618,7 @@ version = "18.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f892c7d766369475ab7b0669f417906302d7c0fb521285c0a0c92e52e7c8e946" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "jsonrpc-core 18.0.0", "jsonrpc-server-utils", "log", @@ -3604,7 +3646,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d802063f7a3c867456955f9d2f15eb3ee0edb5ec9ec2b5526324756759221c0f" dependencies = [ "log", - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -3649,7 +3691,7 @@ dependencies = [ "arrayvec 0.7.2", "async-trait", "fnv", - "futures 0.3.19", + "futures 0.3.21", "http", "jsonrpsee-types", "log", @@ -3682,8 +3724,8 @@ dependencies = [ [[package]] name = "kusama-runtime" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "beefy-primitives", "bitvec", @@ -3696,6 +3738,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", + "kusama-runtime-constants", "log", "pallet-authority-discovery", "pallet-authorship", @@ -3718,6 +3761,7 @@ dependencies = [ "pallet-nicks", "pallet-offences", "pallet-offences-benchmarking", + "pallet-preimage", "pallet-proxy", "pallet-recovery", "pallet-scheduler", @@ -3748,15 +3792,15 @@ dependencies = [ "sp-authority-discovery", "sp-block-builder", "sp-consensus-babe", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-npos-elections", "sp-offchain", "sp-runtime", "sp-session", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "sp-transaction-pool", "sp-version", "static_assertions", @@ -3766,6 +3810,18 @@ dependencies = [ "xcm-executor", ] +[[package]] +name = "kusama-runtime-constants" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" +dependencies = [ + "frame-support", + "polkadot-primitives", + "polkadot-runtime-common", + "smallvec 1.8.0", + "sp-runtime", +] + [[package]] name = "kv-log-macro" version = "1.0.7" @@ -3828,9 +3884,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.117" +version = "0.2.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c" +checksum = "06e509672465a0504304aa87f9f176f2b2b716ed8fb105ebe5c02dc6dce96a94" [[package]] name = "libloading" @@ -3854,9 +3910,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" @@ -3866,7 +3922,7 @@ checksum = "3bec54343492ba5940a6c555e512c6721139835d28c59bc22febece72dfd0d9d" dependencies = [ "atomic", "bytes 1.1.0", - "futures 0.3.19", + "futures 0.3.21", "lazy_static", "libp2p-core", "libp2p-deflate", @@ -3901,17 +3957,18 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.30.0" +version = "0.30.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef22d9bba1e8bcb7ec300073e6802943fe8abb8190431842262b5f1c30abba1" +checksum = "86aad7d54df283db817becded03e611137698a6509d4237a96881976a162340c" dependencies = [ "asn1_der", "bs58", "ed25519-dalek", "either", "fnv", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", + "instant", "lazy_static", "libsecp256k1 0.7.0", "log", @@ -3922,7 +3979,7 @@ dependencies = [ "pin-project 1.0.10", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", "ring", "rw-stream-sink", "sha2 0.9.9", @@ -3940,7 +3997,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51a800adb195f33de63f4b17b63fe64cfc23bf2c6a0d3d0d5321328664e65197" dependencies = [ "flate2", - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", ] @@ -3951,7 +4008,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb8f89d15cb6e3c5bc22afff7513b11bab7856f2872d3cfba86f7f63a06bc498" dependencies = [ "async-std-resolver", - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", "log", "smallvec 1.8.0", @@ -3966,7 +4023,7 @@ checksum = "aab3d7210901ea51b7bae2b581aa34521797af8c4ec738c980bda4a06434067f" dependencies = [ "cuckoofilter", "fnv", - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", "libp2p-swarm", "log", @@ -3987,7 +4044,7 @@ dependencies = [ "byteorder", "bytes 1.1.0", "fnv", - "futures 0.3.19", + "futures 0.3.21", "hex_fmt", "libp2p-core", "libp2p-swarm", @@ -4008,7 +4065,7 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cca1275574183f288ff8b72d535d5ffa5ea9292ef7829af8b47dcb197c7b0dcd" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", "libp2p-swarm", "log", @@ -4030,7 +4087,7 @@ dependencies = [ "bytes 1.1.0", "either", "fnv", - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", "libp2p-swarm", "log", @@ -4054,13 +4111,13 @@ dependencies = [ "async-io", "data-encoding", "dns-parser", - "futures 0.3.19", + "futures 0.3.21", "if-watch", "lazy_static", "libp2p-core", "libp2p-swarm", "log", - "rand 0.8.4", + "rand 0.8.5", "smallvec 1.8.0", "socket2 0.4.4", "void", @@ -4088,7 +4145,7 @@ checksum = "7f2cd64ef597f40e14bfce0497f50ecb63dd6d201c61796daeb4227078834fbf" dependencies = [ "asynchronous-codec 0.6.0", "bytes 1.1.0", - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", "log", "nohash-hasher", @@ -4106,13 +4163,13 @@ checksum = "a8772c7a99088221bb7ca9c5c0574bf55046a7ab4c319f3619b275f28c8fb87a" dependencies = [ "bytes 1.1.0", "curve25519-dalek 3.2.0", - "futures 0.3.19", + "futures 0.3.21", "lazy_static", "libp2p-core", "log", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", "sha2 0.9.9", "snow", "static_assertions", @@ -4126,7 +4183,7 @@ version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80ef7b0ec5cf06530d9eb6cf59ae49d46a2c45663bde31c25a12f682664adbcf" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", "libp2p-swarm", "log", @@ -4143,7 +4200,7 @@ checksum = "5fba1a6ff33e4a274c89a3b1d78b9f34f32af13265cc5c46c16938262d4e945a" dependencies = [ "asynchronous-codec 0.6.0", "bytes 1.1.0", - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", "log", "prost", @@ -4158,7 +4215,7 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f1a458bbda880107b5b36fcb9b5a1ef0c329685da0e203ed692a8ebe64cc92c" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "log", "pin-project 1.0.10", "rand 0.7.3", @@ -4174,8 +4231,8 @@ checksum = "2852b61c90fa8ce3c8fcc2aba76e6cefc20d648f9df29157d6b3a916278ef3e3" dependencies = [ "asynchronous-codec 0.6.0", "bytes 1.1.0", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "libp2p-core", "libp2p-swarm", "log", @@ -4197,13 +4254,13 @@ checksum = "14a6d2b9e7677eff61dc3d2854876aaf3976d84a01ef6664b610c77a0c9407c5" dependencies = [ "asynchronous-codec 0.6.0", "bimap", - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", "libp2p-swarm", "log", "prost", "prost-build", - "rand 0.8.4", + "rand 0.8.5", "sha2 0.9.9", "thiserror", "unsigned-varint 0.7.1", @@ -4219,7 +4276,7 @@ checksum = "a877a4ced6d46bf84677e1974e8cf61fb434af73b2e96fb48d6cb6223a4634d8" dependencies = [ "async-trait", "bytes 1.1.0", - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", "libp2p-swarm", "log", @@ -4237,7 +4294,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f5184a508f223bc100a12665517773fb8730e9f36fc09eefb670bf01b107ae9" dependencies = [ "either", - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", "log", "rand 0.7.3", @@ -4263,8 +4320,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7399c5b6361ef525d41c11fcf51635724f832baf5819b30d3d873eabb4fbae4b" dependencies = [ "async-io", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "if-watch", "ipnet", "libc", @@ -4280,7 +4337,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8b7563e46218165dfd60f64b96f7ce84590d75f53ecbdc74a7dd01450dc5973" dependencies = [ "async-std", - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", "log", ] @@ -4291,7 +4348,7 @@ version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1008a302b73c5020251f9708c653f5ed08368e530e247cc9cd2f109ff30042cf" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "js-sys", "libp2p-core", "parity-send-wrapper", @@ -4306,7 +4363,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22e12df82d1ed64969371a9e65ea92b91064658604cc2576c2757f18ead9a1cf" dependencies = [ "either", - "futures 0.3.19", + "futures 0.3.21", "futures-rustls", "libp2p-core", "log", @@ -4323,7 +4380,7 @@ version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e7362abb8867d7187e7e93df17f460d554c997fc5c8ac57dc1259057f6889af" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "libp2p-core", "parking_lot 0.11.2", "thiserror", @@ -4374,7 +4431,7 @@ dependencies = [ "libsecp256k1-core 0.3.0", "libsecp256k1-gen-ecmult 0.3.0", "libsecp256k1-gen-genmult 0.3.0", - "rand 0.8.4", + "rand 0.8.5", "serde", "sha2 0.9.9", "typenum 1.15.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4476,9 +4533,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.0.28" +version = "0.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "687387ff42ec7ea4f2149035a5675fedb675d26f98db90a1846ac63d3addb5f5" +checksum = "a261afc61b7a5e323933b402ca6a1765183687c614789b1e4db7762ed4230bca" [[package]] name = "lock_api" @@ -4623,9 +4680,9 @@ dependencies = [ [[package]] name = "memmap2" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe3179b85e1fd8b14447cbebadb75e45a1002f541b925f0bfec366d56a81c56d" +checksum = "057a3db23999c867821a7a59feb06a578fcb03685e983dff90daf9e7d24ac08f" dependencies = [ "libc", ] @@ -4650,6 +4707,17 @@ dependencies = [ "parity-util-mem", ] +[[package]] +name = "memory-db" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d505169b746dacf02f7d14d8c80b34edfd8212159c63d23c977739a0d960c626" +dependencies = [ + "hash-db", + "hashbrown 0.11.2", + "parity-util-mem", +] + [[package]] name = "memory-lru" version = "0.1.0" @@ -4679,12 +4747,12 @@ dependencies = [ [[package]] name = "metered-channel" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "derive_more", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "thiserror", "tracing", ] @@ -4695,8 +4763,8 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd2c2cc134e57461f0898b0e921f0a7819b5e3f3a4335b9aa390ce81a5f36fb9" dependencies = [ - "futures 0.3.19", - "rand 0.8.4", + "futures 0.3.21", + "rand 0.8.5", "thrift", ] @@ -4801,10 +4869,10 @@ dependencies = [ "primitives", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] @@ -4962,7 +5030,7 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "424f6e86263cd5294cbd7f1e95746b95aca0e0d66bff31e5a40d6baa87b4aa99" dependencies = [ - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro-error", "proc-macro2", "quote", @@ -4983,7 +5051,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56a336acba8bc87c8876f6425407dbbe6c417bf478b22015f8fb0994ef3bc0ab" dependencies = [ "bytes 1.1.0", - "futures 0.3.19", + "futures 0.3.21", "log", "pin-project 1.0.10", "smallvec 1.8.0", @@ -5011,7 +5079,7 @@ dependencies = [ "move-vm-types", "parity-scale-codec", "parity-scale-codec-derive", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", + "sp-io 4.0.0-dev", "stdlib", ] @@ -5027,7 +5095,7 @@ dependencies = [ "num-complex", "num-rational 0.4.0", "num-traits", - "rand 0.8.4", + "rand 0.8.5", "rand_distr", "simba", "typenum 1.15.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5050,7 +5118,16 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a8690bf09abf659851e58cd666c3d37ac6af07c2bd7a9e332cfba471715775" dependencies = [ - "rand 0.8.4", + "rand 0.8.5", +] + +[[package]] +name = "nanorand" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "729eb334247daa1803e0a094d0a5c55711b85571179f5ec6e53eccfdf7008958" +dependencies = [ + "getrandom 0.2.4", ] [[package]] @@ -5066,14 +5143,15 @@ dependencies = [ [[package]] name = "nimbus-consensus" -version = "0.1.0" -source = "git+https://github.com/pontem-network/nimbus.git?branch=polkadot-v0.9.13#e4b6e1aa61ba83ba1909f901a1936916840b6774" +version = "0.9.0" +source = "git+https://github.com/pontem-network/nimbus?branch=polkadot-v0.9.16#fe112c616306445bfe408865a629f27ad5980b9e" dependencies = [ "async-trait", "cumulus-client-consensus-common", "cumulus-primitives-core", "cumulus-primitives-parachain-inherent", - "futures 0.3.19", + "cumulus-relay-chain-interface", + "futures 0.3.21", "log", "nimbus-primitives", "parity-scale-codec", @@ -5081,24 +5159,24 @@ dependencies = [ "polkadot-client", "sc-client-api", "sc-consensus", + "sc-consensus-manual-seal", "sp-api", "sp-application-crypto", "sp-block-builder", "sp-blockchain", "sp-consensus", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-keystore 0.10.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", "substrate-prometheus-endpoint", "tracing", ] [[package]] name = "nimbus-primitives" -version = "0.1.0" -source = "git+https://github.com/pontem-network/nimbus.git?branch=polkadot-v0.9.13#e4b6e1aa61ba83ba1909f901a1936916840b6774" +version = "0.9.0" +source = "git+https://github.com/pontem-network/nimbus?branch=polkadot-v0.9.16#fe112c616306445bfe408865a629f27ad5980b9e" dependencies = [ "async-trait", "frame-support", @@ -5109,7 +5187,7 @@ dependencies = [ "sp-application-crypto", "sp-inherents", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] @@ -5137,9 +5215,9 @@ dependencies = [ [[package]] name = "ntapi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" dependencies = [ "winapi 0.3.9", ] @@ -5287,7 +5365,7 @@ dependencies = [ [[package]] name = "orml-currencies" version = "0.4.1-dev" -source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5#88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=213f743af2d6d2c94f235613d7e7ff21b093297c#213f743af2d6d2c94f235613d7e7ff21b093297c" dependencies = [ "frame-support", "frame-system", @@ -5295,15 +5373,15 @@ dependencies = [ "orml-utilities", "parity-scale-codec", "scale-info", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "orml-tokens" version = "0.4.1-dev" -source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5#88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=213f743af2d6d2c94f235613d7e7ff21b093297c#213f743af2d6d2c94f235613d7e7ff21b093297c" dependencies = [ "frame-support", "frame-system", @@ -5312,13 +5390,13 @@ dependencies = [ "scale-info", "serde", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "orml-traits" version = "0.4.1-dev" -source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5#88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=213f743af2d6d2c94f235613d7e7ff21b093297c#213f743af2d6d2c94f235613d7e7ff21b093297c" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -5327,64 +5405,64 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", ] [[package]] name = "orml-unknown-tokens" version = "0.4.1-dev" -source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5#88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=213f743af2d6d2c94f235613d7e7ff21b093297c#213f743af2d6d2c94f235613d7e7ff21b093297c" dependencies = [ "frame-support", "frame-system", "orml-xcm-support", "parity-scale-codec", "scale-info", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", ] [[package]] name = "orml-utilities" version = "0.4.1-dev" -source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5#88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=213f743af2d6d2c94f235613d7e7ff21b093297c#213f743af2d6d2c94f235613d7e7ff21b093297c" dependencies = [ "frame-support", "parity-scale-codec", "scale-info", "serde", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "orml-xcm" version = "0.4.1-dev" -source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5#88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=213f743af2d6d2c94f235613d7e7ff21b093297c#213f743af2d6d2c94f235613d7e7ff21b093297c" dependencies = [ "frame-support", "frame-system", "pallet-xcm", "parity-scale-codec", "scale-info", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", ] [[package]] name = "orml-xcm-support" version = "0.4.1-dev" -source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5#88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=213f743af2d6d2c94f235613d7e7ff21b093297c#213f743af2d6d2c94f235613d7e7ff21b093297c" dependencies = [ "frame-support", "orml-traits", "parity-scale-codec", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", "xcm-executor", ] @@ -5392,7 +5470,7 @@ dependencies = [ [[package]] name = "orml-xtokens" version = "0.4.1-dev" -source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5#88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" +source = "git+https://github.com/open-web3-stack/open-runtime-module-library?rev=213f743af2d6d2c94f235613d7e7ff21b093297c#213f743af2d6d2c94f235613d7e7ff21b093297c" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -5402,9 +5480,9 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", "xcm-executor", ] @@ -5420,8 +5498,8 @@ dependencies = [ [[package]] name = "pallet-author-inherent" -version = "0.1.0" -source = "git+https://github.com/pontem-network/nimbus.git?branch=polkadot-v0.9.13#e4b6e1aa61ba83ba1909f901a1936916840b6774" +version = "0.9.0" +source = "git+https://github.com/pontem-network/nimbus?branch=polkadot-v0.9.16#fe112c616306445bfe408865a629f27ad5980b9e" dependencies = [ "frame-support", "frame-system", @@ -5434,12 +5512,12 @@ dependencies = [ "sp-authorship", "sp-inherents", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-author-mapping" -version = "2.0.4" +version = "2.0.5" dependencies = [ "frame-benchmarking", "frame-support", @@ -5450,16 +5528,16 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-author-slot-filter" -version = "0.1.0" -source = "git+https://github.com/pontem-network/nimbus.git?branch=polkadot-v0.9.13#e4b6e1aa61ba83ba1909f901a1936916840b6774" +version = "0.9.0" +source = "git+https://github.com/pontem-network/nimbus?branch=polkadot-v0.9.16#fe112c616306445bfe408865a629f27ad5980b9e" dependencies = [ "frame-support", "frame-system", @@ -5468,15 +5546,15 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", @@ -5486,13 +5564,13 @@ dependencies = [ "sp-application-crypto", "sp-authority-discovery", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", @@ -5501,13 +5579,13 @@ dependencies = [ "scale-info", "sp-authorship", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-babe" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -5521,17 +5599,17 @@ dependencies = [ "sp-application-crypto", "sp-consensus-babe", "sp-consensus-vrf", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", "sp-session", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-bags-list" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5541,17 +5619,17 @@ dependencies = [ "pallet-balances", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-tracing 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", + "sp-tracing 4.0.0", ] [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -5560,13 +5638,13 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-beefy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "beefy-primitives", "frame-support", @@ -5576,13 +5654,13 @@ dependencies = [ "scale-info", "serde", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-beefy-mmr" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "beefy-merkle-tree", "beefy-primitives", @@ -5598,16 +5676,16 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-bounties" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -5616,16 +5694,16 @@ dependencies = [ "pallet-treasury", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-bridge-dispatch" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bp-message-dispatch", "bp-runtime", @@ -5634,15 +5712,15 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-bridge-grandpa" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bp-header-chain", "bp-runtime", @@ -5657,19 +5735,18 @@ dependencies = [ "serde", "sp-finality-grandpa", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", + "sp-trie 4.0.0", ] [[package]] name = "pallet-bridge-messages" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bitvec", "bp-message-dispatch", "bp-messages", - "bp-rialto", "bp-runtime", "frame-support", "frame-system", @@ -5678,15 +5755,15 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-collective" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -5694,16 +5771,16 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-democracy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -5711,15 +5788,15 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5730,20 +5807,20 @@ dependencies = [ "rand 0.7.3", "scale-info", "sp-arithmetic", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-npos-elections", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "static_assertions", - "strum", - "strum_macros", + "strum 0.22.0", + "strum_macros 0.23.1", ] [[package]] name = "pallet-elections-phragmen" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -5751,17 +5828,17 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-npos-elections", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-gilt" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -5770,13 +5847,13 @@ dependencies = [ "scale-info", "sp-arithmetic", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -5787,19 +5864,19 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-application-crypto", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-finality-grandpa", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", "sp-session", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-identity" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "enumflags2", "frame-benchmarking", @@ -5807,15 +5884,15 @@ dependencies = [ "frame-system", "parity-scale-codec", "scale-info", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-im-online" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -5825,34 +5902,34 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-application-crypto", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-indices" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-keyring", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-membership" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -5860,16 +5937,16 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-mmr" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "ckb-merkle-mountain-range", "frame-benchmarking", @@ -5878,16 +5955,16 @@ dependencies = [ "pallet-mmr-primitives", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-mmr-primitives" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", @@ -5895,15 +5972,15 @@ dependencies = [ "parity-scale-codec", "serde", "sp-api", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-mmr-rpc" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "jsonrpc-core 18.0.0", "jsonrpc-core-client 18.0.0", @@ -5913,43 +5990,43 @@ dependencies = [ "serde", "sp-api", "sp-blockchain", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", ] [[package]] name = "pallet-multisig" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", "scale-info", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-nicks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", "parity-scale-codec", "scale-info", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-offences" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", @@ -5960,13 +6037,13 @@ dependencies = [ "serde", "sp-runtime", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-offences-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -5983,28 +6060,44 @@ dependencies = [ "scale-info", "sp-runtime", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", +] + +[[package]] +name = "pallet-preimage" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", + "sp-runtime", + "sp-std 4.0.0", ] [[package]] name = "pallet-proxy" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", "scale-info", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-randomness-collective-flip" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", @@ -6012,27 +6105,27 @@ dependencies = [ "safe-mix", "scale-info", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-recovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", "parity-scale-codec", "scale-info", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-scheduler" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -6040,15 +6133,15 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", @@ -6057,19 +6150,19 @@ dependencies = [ "pallet-timestamp", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", "sp-session", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", + "sp-trie 4.0.0", ] [[package]] name = "pallet-session-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -6079,13 +6172,13 @@ dependencies = [ "rand 0.7.3", "sp-runtime", "sp-session", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-society" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", @@ -6093,13 +6186,13 @@ dependencies = [ "rand_chacha 0.2.2", "scale-info", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -6113,18 +6206,18 @@ dependencies = [ "scale-info", "serde", "sp-application-crypto", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-staking-reward-curve" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -6133,7 +6226,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-fn" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "log", "sp-arithmetic", @@ -6142,21 +6235,21 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", "parity-scale-codec", "scale-info", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -6165,16 +6258,16 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "sp-timestamp", ] [[package]] name = "pallet-tips" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -6184,16 +6277,16 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-transaction-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-support", "frame-system", @@ -6201,16 +6294,16 @@ dependencies = [ "scale-info", "serde", "smallvec 1.8.0", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-transaction-payment-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "jsonrpc-core 18.0.0", "jsonrpc-core-client 18.0.0", @@ -6219,7 +6312,7 @@ dependencies = [ "parity-scale-codec", "sp-api", "sp-blockchain", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-rpc", "sp-runtime", ] @@ -6227,7 +6320,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -6238,7 +6331,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -6249,29 +6342,29 @@ dependencies = [ "scale-info", "serde", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-utility" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", "frame-system", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-benchmarking", "frame-support", @@ -6280,13 +6373,13 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "pallet-xcm" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "frame-support", "frame-system", @@ -6294,17 +6387,17 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", "xcm-executor", ] [[package]] name = "pallet-xcm-benchmarks" -version = "0.9.8" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "frame-benchmarking", "frame-support", @@ -6313,7 +6406,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", "xcm-executor", ] @@ -6321,7 +6414,7 @@ dependencies = [ [[package]] name = "parachain-info" version = "0.1.0" -source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.13#05cc5f0e2acacc18796f45ffa3c7b4626fd1046d" +source = "git+https://github.com/paritytech/cumulus?branch=polkadot-v0.9.16#86f76c5619c64d1300315612695ad4b4fcd0f562" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -6345,10 +6438,10 @@ dependencies = [ "scale-info", "serde", "similar-asserts", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "substrate-fixed", ] @@ -6367,7 +6460,7 @@ dependencies = [ "lz4", "memmap2 0.2.3", "parking_lot 0.11.2", - "rand 0.8.4", + "rand 0.8.5", "snap", ] @@ -6391,7 +6484,7 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1557010476e0595c9b568d16dcfb81b93cdeb157612726f5170d31aa707bed27" dependencies = [ - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -6409,7 +6502,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9981e32fb75e004cc148f5fb70342f393830e0a4aa62e3cc93b50976218d42b6" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "libc", "log", "rand 0.7.3", @@ -6737,10 +6830,10 @@ checksum = "e8d0eef3571242013a0d5dc84861c3ae4a652e56e12adf8bdc26ff5f8cb34c94" [[package]] name = "polkadot-approval-distribution" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "polkadot-node-network-protocol", "polkadot-node-primitives", "polkadot-node-subsystem", @@ -6751,10 +6844,10 @@ dependencies = [ [[package]] name = "polkadot-availability-bitfield-distribution" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "polkadot-node-network-protocol", "polkadot-node-subsystem", "polkadot-node-subsystem-util", @@ -6764,11 +6857,11 @@ dependencies = [ [[package]] name = "polkadot-availability-distribution" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "derive_more", - "futures 0.3.19", + "futures 0.3.21", "lru 0.7.2", "parity-scale-codec", "polkadot-erasure-coding", @@ -6777,19 +6870,19 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "rand 0.8.4", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "rand 0.8.5", + "sp-core 4.1.0-dev", + "sp-keystore 0.10.0", "thiserror", "tracing", ] [[package]] name = "polkadot-availability-recovery" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "lru 0.7.2", "parity-scale-codec", "polkadot-erasure-coding", @@ -6798,7 +6891,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "rand 0.8.4", + "rand 0.8.5", "sc-network", "thiserror", "tracing", @@ -6806,18 +6899,21 @@ dependencies = [ [[package]] name = "polkadot-cli" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "frame-benchmarking-cli", - "futures 0.3.19", + "futures 0.3.21", "log", "polkadot-node-core-pvf", + "polkadot-node-metrics", + "polkadot-performance-test", "polkadot-service", "sc-cli", "sc-service", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sc-tracing", + "sp-core 4.1.0-dev", + "sp-trie 4.0.0", "structopt", "substrate-build-script-utils", "thiserror", @@ -6826,8 +6922,8 @@ dependencies = [ [[package]] name = "polkadot-client" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "beefy-primitives", "frame-benchmarking", @@ -6851,27 +6947,27 @@ dependencies = [ "sp-offchain", "sp-runtime", "sp-session", - "sp-storage 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-storage 4.0.0", "sp-transaction-pool", "westend-runtime", ] [[package]] name = "polkadot-collator-protocol" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "always-assert", "derive_more", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "polkadot-node-network-protocol", "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-keystore 0.10.0", "sp-runtime", "thiserror", "tracing", @@ -6879,24 +6975,24 @@ dependencies = [ [[package]] name = "polkadot-core-primitives" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "parity-scale-codec", "parity-util-mem", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "polkadot-dispute-distribution" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "derive_more", - "futures 0.3.19", + "futures 0.3.21", "lru 0.7.2", "parity-scale-codec", "polkadot-erasure-coding", @@ -6907,52 +7003,52 @@ dependencies = [ "polkadot-primitives", "sc-network", "sp-application-crypto", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-keystore 0.10.0", "thiserror", "tracing", ] [[package]] name = "polkadot-erasure-coding" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "parity-scale-codec", "polkadot-node-primitives", "polkadot-primitives", "reed-solomon-novelpoly", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-trie 4.0.0", "thiserror", ] [[package]] name = "polkadot-gossip-support" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "polkadot-node-network-protocol", "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "rand 0.8.4", + "rand 0.8.5", "rand_chacha 0.3.1", "sc-network", "sp-application-crypto", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-keystore 0.10.0", "tracing", ] [[package]] name = "polkadot-network-bridge" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "async-trait", - "futures 0.3.19", + "futures 0.3.21", "parity-scale-codec", "parking_lot 0.11.2", "polkadot-node-network-protocol", @@ -6967,17 +7063,17 @@ dependencies = [ [[package]] name = "polkadot-node-collation-generation" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "parity-scale-codec", "polkadot-erasure-coding", "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-maybe-compressed-blob", "thiserror", "tracing", @@ -6985,13 +7081,13 @@ dependencies = [ [[package]] name = "polkadot-node-core-approval-voting" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bitvec", "derive_more", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "kvdb", "lru 0.7.2", "merlin", @@ -7013,12 +7109,12 @@ dependencies = [ [[package]] name = "polkadot-node-core-av-store" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bitvec", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "kvdb", "parity-scale-codec", "polkadot-erasure-coding", @@ -7033,32 +7129,32 @@ dependencies = [ [[package]] name = "polkadot-node-core-backing" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bitvec", - "futures 0.3.19", + "futures 0.3.21", "polkadot-erasure-coding", "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", "polkadot-statement-table", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-keystore 0.10.0", "thiserror", "tracing", ] [[package]] name = "polkadot-node-core-bitfield-signing" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-keystore 0.10.0", "thiserror", "tracing", "wasm-timer", @@ -7066,11 +7162,11 @@ dependencies = [ [[package]] name = "polkadot-node-core-candidate-validation" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "async-trait", - "futures 0.3.19", + "futures 0.3.21", "parity-scale-codec", "polkadot-node-core-pvf", "polkadot-node-primitives", @@ -7084,10 +7180,10 @@ dependencies = [ [[package]] name = "polkadot-node-core-chain-api" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", @@ -7099,11 +7195,11 @@ dependencies = [ [[package]] name = "polkadot-node-core-chain-selection" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "kvdb", "parity-scale-codec", "polkadot-node-primitives", @@ -7116,13 +7212,12 @@ dependencies = [ [[package]] name = "polkadot-node-core-dispute-coordinator" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "bitvec", - "derive_more", - "futures 0.3.19", + "futures 0.3.21", "kvdb", + "lru 0.7.2", "parity-scale-codec", "polkadot-node-primitives", "polkadot-node-subsystem", @@ -7133,27 +7228,14 @@ dependencies = [ "tracing", ] -[[package]] -name = "polkadot-node-core-dispute-participation" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" -dependencies = [ - "futures 0.3.19", - "polkadot-node-primitives", - "polkadot-node-subsystem", - "polkadot-primitives", - "thiserror", - "tracing", -] - [[package]] name = "polkadot-node-core-parachains-inherent" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "async-trait", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "polkadot-node-subsystem", "polkadot-primitives", "sp-blockchain", @@ -7165,72 +7247,89 @@ dependencies = [ [[package]] name = "polkadot-node-core-provisioner" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bitvec", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", + "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", + "rand 0.8.5", "thiserror", "tracing", ] [[package]] name = "polkadot-node-core-pvf" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "always-assert", "assert_matches", "async-process", "async-std", - "futures 0.3.19", - "futures-timer 3.0.2", - "libc", + "futures 0.3.21", + "futures-timer", "parity-scale-codec", "pin-project 1.0.10", "polkadot-core-primitives", "polkadot-node-subsystem-util", "polkadot-parachain", - "rand 0.8.4", + "rand 0.8.5", "sc-executor", "sc-executor-common", "sc-executor-wasmtime", "slotmap", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-externalities 0.10.0", + "sp-io 4.0.0", "sp-maybe-compressed-blob", - "sp-tracing 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-wasm-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-tracing 4.0.0", + "sp-wasm-interface 4.1.0-dev", "tracing", ] [[package]] -name = "polkadot-node-core-runtime-api" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +name = "polkadot-node-core-pvf-checker" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "futures 0.3.19", - "memory-lru", - "parity-util-mem", + "futures 0.3.21", + "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-node-subsystem-util", + "polkadot-overseer", "polkadot-primitives", - "sp-api", - "sp-authority-discovery", - "sp-consensus-babe", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-keystore 0.10.0", + "thiserror", "tracing", ] [[package]] -name = "polkadot-node-jaeger" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +name = "polkadot-node-core-runtime-api" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" +dependencies = [ + "futures 0.3.21", + "memory-lru", + "parity-util-mem", + "polkadot-node-subsystem", + "polkadot-node-subsystem-util", + "polkadot-primitives", + "sp-api", + "sp-authority-discovery", + "sp-consensus-babe", + "sp-core 4.1.0-dev", + "tracing", +] + +[[package]] +name = "polkadot-node-jaeger" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "async-std", "lazy_static", @@ -7241,46 +7340,54 @@ dependencies = [ "polkadot-node-primitives", "polkadot-primitives", "sc-network", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "thiserror", ] [[package]] name = "polkadot-node-metrics" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "futures 0.3.19", - "futures-timer 3.0.2", + "bs58", + "futures 0.3.21", + "futures-timer", + "log", "metered-channel", + "parity-scale-codec", + "polkadot-primitives", + "sc-cli", + "sc-service", + "sc-tracing", "substrate-prometheus-endpoint", + "tracing", ] [[package]] name = "polkadot-node-network-protocol" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "async-trait", "derive_more", - "futures 0.3.19", + "futures 0.3.21", "parity-scale-codec", "polkadot-node-jaeger", "polkadot-node-primitives", "polkadot-primitives", "sc-authority-discovery", "sc-network", - "strum", + "strum 0.23.0", "thiserror", ] [[package]] name = "polkadot-node-primitives" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bounded-vec", - "futures 0.3.19", + "futures 0.3.21", "parity-scale-codec", "polkadot-parachain", "polkadot-primitives", @@ -7289,8 +7396,8 @@ dependencies = [ "sp-application-crypto", "sp-consensus-babe", "sp-consensus-vrf", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-keystore 0.10.0", "sp-maybe-compressed-blob", "thiserror", "zstd", @@ -7298,8 +7405,8 @@ dependencies = [ [[package]] name = "polkadot-node-subsystem" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "polkadot-node-jaeger", "polkadot-node-subsystem-types", @@ -7308,11 +7415,11 @@ dependencies = [ [[package]] name = "polkadot-node-subsystem-types" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "derive_more", - "futures 0.3.19", + "futures 0.3.21", "polkadot-node-jaeger", "polkadot-node-network-protocol", "polkadot-node-primitives", @@ -7327,12 +7434,12 @@ dependencies = [ [[package]] name = "polkadot-node-subsystem-util" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "async-trait", "derive_more", - "futures 0.3.19", + "futures 0.3.21", "itertools", "lru 0.7.2", "metered-channel", @@ -7341,24 +7448,25 @@ dependencies = [ "polkadot-node-jaeger", "polkadot-node-metrics", "polkadot-node-network-protocol", + "polkadot-node-primitives", "polkadot-node-subsystem", "polkadot-overseer", "polkadot-primitives", - "rand 0.8.4", + "rand 0.8.5", "sp-application-crypto", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-keystore 0.10.0", "thiserror", "tracing", ] [[package]] name = "polkadot-overseer" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "lru 0.7.2", "parity-util-mem", "parking_lot 0.11.2", @@ -7375,12 +7483,12 @@ dependencies = [ [[package]] name = "polkadot-overseer-gen" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "async-trait", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "metered-channel", "pin-project 1.0.10", "polkadot-node-network-protocol", @@ -7392,10 +7500,10 @@ dependencies = [ [[package]] name = "polkadot-overseer-gen-proc-macro" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -7403,8 +7511,8 @@ dependencies = [ [[package]] name = "polkadot-parachain" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "derive_more", "frame-support", @@ -7413,15 +7521,30 @@ dependencies = [ "polkadot-core-primitives", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", +] + +[[package]] +name = "polkadot-performance-test" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" +dependencies = [ + "env_logger", + "kusama-runtime", + "log", + "polkadot-erasure-coding", + "polkadot-node-core-pvf", + "polkadot-node-primitives", + "quote", + "thiserror", ] [[package]] name = "polkadot-primitives" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bitvec", "frame-system", @@ -7437,21 +7560,21 @@ dependencies = [ "sp-arithmetic", "sp-authority-discovery", "sp-consensus-slots", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", + "sp-keystore 0.10.0", "sp-runtime", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", + "sp-trie 4.0.0", "sp-version", ] [[package]] name = "polkadot-rpc" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "beefy-gadget", "beefy-gadget-rpc", @@ -7474,15 +7597,15 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-babe", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-keystore 0.10.0", "sp-runtime", "substrate-frame-rpc-system", ] [[package]] name = "polkadot-runtime" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "beefy-primitives", "bitvec", @@ -7516,6 +7639,7 @@ dependencies = [ "pallet-nicks", "pallet-offences", "pallet-offences-benchmarking", + "pallet-preimage", "pallet-proxy", "pallet-scheduler", "pallet-session", @@ -7533,6 +7657,7 @@ dependencies = [ "parity-scale-codec", "polkadot-primitives", "polkadot-runtime-common", + "polkadot-runtime-constants", "polkadot-runtime-parachains", "rustc-hex", "scale-info", @@ -7543,15 +7668,15 @@ dependencies = [ "sp-authority-discovery", "sp-block-builder", "sp-consensus-babe", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-npos-elections", "sp-offchain", "sp-runtime", "sp-session", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "sp-transaction-pool", "sp-version", "static_assertions", @@ -7563,8 +7688,8 @@ dependencies = [ [[package]] name = "polkadot-runtime-common" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "beefy-primitives", "bitvec", @@ -7596,22 +7721,46 @@ dependencies = [ "serde_derive", "slot-range-helper", "sp-api", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-npos-elections", "sp-runtime", "sp-session", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "static_assertions", "xcm", ] +[[package]] +name = "polkadot-runtime-constants" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" +dependencies = [ + "frame-support", + "polkadot-primitives", + "polkadot-runtime-common", + "smallvec 1.8.0", + "sp-runtime", +] + +[[package]] +name = "polkadot-runtime-metrics" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" +dependencies = [ + "bs58", + "parity-scale-codec", + "polkadot-primitives", + "sp-std 4.0.0", + "sp-tracing 4.0.0", +] + [[package]] name = "polkadot-runtime-parachains" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "bitflags", "bitvec", @@ -7630,36 +7779,38 @@ dependencies = [ "pallet-vesting", "parity-scale-codec", "polkadot-primitives", - "rand 0.8.4", + "polkadot-runtime-metrics", + "rand 0.8.5", "rand_chacha 0.3.1", "rustc-hex", "scale-info", "serde", "sp-api", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", + "sp-keystore 0.10.0", "sp-runtime", "sp-session", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", "xcm-executor", ] [[package]] name = "polkadot-service" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "async-trait", "beefy-gadget", "beefy-primitives", "frame-system-rpc-runtime-api", - "futures 0.3.19", + "futures 0.3.21", "hex-literal", "kusama-runtime", + "kusama-runtime-constants", "kvdb", "kvdb-rocksdb", "lru 0.7.2", @@ -7686,9 +7837,9 @@ dependencies = [ "polkadot-node-core-chain-api", "polkadot-node-core-chain-selection", "polkadot-node-core-dispute-coordinator", - "polkadot-node-core-dispute-participation", "polkadot-node-core-parachains-inherent", "polkadot-node-core-provisioner", + "polkadot-node-core-pvf-checker", "polkadot-node-core-runtime-api", "polkadot-node-network-protocol", "polkadot-node-primitives", @@ -7699,6 +7850,7 @@ dependencies = [ "polkadot-primitives", "polkadot-rpc", "polkadot-runtime", + "polkadot-runtime-constants", "polkadot-runtime-parachains", "polkadot-statement-distribution", "rococo-runtime", @@ -7728,33 +7880,34 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-babe", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-finality-grandpa", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", + "sp-keystore 0.10.0", "sp-offchain", "sp-runtime", "sp-session", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-storage 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", + "sp-storage 4.0.0", "sp-timestamp", "sp-transaction-pool", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-trie 4.0.0", "substrate-prometheus-endpoint", "thiserror", "tracing", "westend-runtime", + "westend-runtime-constants", ] [[package]] name = "polkadot-statement-distribution" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "arrayvec 0.5.2", "derive_more", - "futures 0.3.19", + "futures 0.3.21", "indexmap 1.8.0", "parity-scale-codec", "polkadot-node-network-protocol", @@ -7762,7 +7915,7 @@ dependencies = [ "polkadot-node-subsystem", "polkadot-node-subsystem-util", "polkadot-primitives", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-keystore 0.10.0", "sp-staking", "thiserror", "tracing", @@ -7770,12 +7923,12 @@ dependencies = [ [[package]] name = "polkadot-statement-table" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "parity-scale-codec", "polkadot-primitives", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", ] [[package]] @@ -7827,9 +7980,12 @@ dependencies = [ "cumulus-client-service", "cumulus-primitives-core", "cumulus-primitives-parachain-inherent", + "cumulus-relay-chain-interface", + "cumulus-relay-chain-local", + "flume", "frame-benchmarking", "frame-benchmarking-cli", - "futures 0.3.19", + "futures 0.3.21", "jsonrpc-core 18.0.0", "log", "mvm", @@ -7866,10 +8022,10 @@ dependencies = [ "sp-block-builder", "sp-blockchain", "sp-consensus", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-finality-grandpa", "sp-inherents", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-keystore 0.10.0", "sp-mvm-rpc", "sp-mvm-rpc-runtime", "sp-offchain", @@ -7897,7 +8053,7 @@ dependencies = [ "cumulus-primitives-core", "cumulus-primitives-timestamp", "cumulus-primitives-utility", - "env_logger 0.9.0", + "env_logger", "frame-benchmarking", "frame-executive", "frame-support", @@ -7943,15 +8099,15 @@ dependencies = [ "smallvec 1.8.0", "sp-api", "sp-block-builder", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-mvm", "sp-mvm-rpc-runtime", "sp-offchain", "sp-runtime", "sp-session", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "sp-transaction-pool", "sp-version", "substrate-wasm-builder", @@ -8003,9 +8159,9 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] @@ -8019,9 +8175,9 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83" +checksum = "9dada8c9981fcf32929c3c0f0cd796a9284aca335565227ed88c83babb1d43dc" dependencies = [ "thiserror", "toml", @@ -8129,24 +8285,13 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd136ff4382c4753fc061cb9e4712ab2af263376b95bbd5bd8cd50c020b78e69" +checksum = "6eca0fa5dd7c4c96e184cec588f0b1db1ee3165e678db21c09793105acb17e6f" dependencies = [ "cc", ] -[[package]] -name = "pwasm-utils" -version = "0.18.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "880b3384fb00b8f6ecccd5d358b93bd2201900ae3daad213791d1864f6441f5c" -dependencies = [ - "byteorder", - "log", - "parity-wasm 0.42.2", -] - [[package]] name = "quick-error" version = "1.2.3" @@ -8195,20 +8340,19 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc 0.2.0", + "rand_hc", "rand_pcg", ] [[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.1", "rand_core 0.6.3", - "rand_hc 0.3.1", ] [[package]] @@ -8256,7 +8400,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" dependencies = [ "num-traits", - "rand 0.8.4", + "rand 0.8.5", ] [[package]] @@ -8268,15 +8412,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rand_hc" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" -dependencies = [ - "rand_core 0.6.3", -] - [[package]] name = "rand_pcg" version = "0.2.1" @@ -8377,9 +8512,9 @@ dependencies = [ [[package]] name = "regalloc" -version = "0.0.32" +version = "0.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6304468554ed921da3d32c355ea107b8d13d7b8996c3adfb7aab48d3bc321f4" +checksum = "7d808cff91dfca7b239d40b972ba628add94892b1d9e19a842aedc5cfae8ab1a" dependencies = [ "log", "rustc-hash", @@ -8427,16 +8562,16 @@ dependencies = [ [[package]] name = "remote-externalities" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "env_logger 0.9.0", + "env_logger", "jsonrpsee", "log", "parity-scale-codec", "serde", "serde_json", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", "sp-version", ] @@ -8475,7 +8610,7 @@ dependencies = [ "cc", "libc", "once_cell", - "spin", + "spin 0.5.2", "untrusted", "web-sys", "winapi 0.3.9", @@ -8503,8 +8638,8 @@ dependencies = [ [[package]] name = "rococo-runtime" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "beefy-primitives", "bp-messages", @@ -8551,6 +8686,7 @@ dependencies = [ "polkadot-primitives", "polkadot-runtime-common", "polkadot-runtime-parachains", + "rococo-runtime-constants", "scale-info", "serde", "serde_derive", @@ -8559,14 +8695,14 @@ dependencies = [ "sp-authority-discovery", "sp-block-builder", "sp-consensus-babe", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-offchain", "sp-runtime", "sp-session", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "sp-transaction-pool", "sp-version", "substrate-wasm-builder", @@ -8576,30 +8712,25 @@ dependencies = [ ] [[package]] -name = "rpassword" -version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc936cf8a7ea60c58f030fd36a612a48f440610214dc54bc36431f9ea0c3efb" +name = "rococo-runtime-constants" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ - "libc", - "winapi 0.3.9", + "frame-support", + "polkadot-primitives", + "polkadot-runtime-common", + "smallvec 1.8.0", + "sp-runtime", ] [[package]] -name = "rsix" -version = "0.23.9" +name = "rpassword" +version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f64c5788d5aab8b75441499d99576a24eb09f76fb267b36fec7e3d970c66431" +checksum = "ffc936cf8a7ea60c58f030fd36a612a48f440610214dc54bc36431f9ea0c3efb" dependencies = [ - "bitflags", - "cc", - "errno", - "io-lifetimes", - "itoa 0.4.8", "libc", - "linux-raw-sys", - "once_cell", - "rustc_version 0.4.0", + "winapi 0.3.9", ] [[package]] @@ -8644,7 +8775,21 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.4", + "semver 1.0.5", +] + +[[package]] +name = "rustix" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2dcfc2778a90e38f56a708bfc90572422e11d6c7ee233d053d1f782cf9df6d2" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "winapi 0.3.9", ] [[package]] @@ -8672,13 +8817,19 @@ dependencies = [ "security-framework", ] +[[package]] +name = "rustversion" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" + [[package]] name = "rw-stream-sink" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4da5fcb054c46f5a5dff833b129285a93d3f0179531735e6c866e8cc307d2020" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "pin-project 0.4.29", "static_assertions", ] @@ -8719,23 +8870,23 @@ dependencies = [ [[package]] name = "sc-allocator" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "log", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-wasm-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-wasm-interface 4.1.0-dev", "thiserror", ] [[package]] name = "sc-authority-discovery" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", "derive_more", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "ip_network", "libp2p", "log", @@ -8748,8 +8899,8 @@ dependencies = [ "sp-api", "sp-authority-discovery", "sp-blockchain", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-keystore 0.10.0", "sp-runtime", "substrate-prometheus-endpoint", ] @@ -8757,10 +8908,10 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "log", "parity-scale-codec", "sc-block-builder", @@ -8771,7 +8922,7 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-consensus", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", "sp-runtime", "substrate-prometheus-endpoint", @@ -8780,42 +8931,42 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", "sc-client-api", "sp-api", "sp-block-builder", "sp-blockchain", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", ] [[package]] name = "sc-chain-spec" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "impl-trait-for-tuples", - "memmap2 0.5.2", + "memmap2 0.5.3", "parity-scale-codec", "sc-chain-spec-derive", "sc-network", "sc-telemetry", "serde", "serde_json", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", ] [[package]] name = "sc-chain-spec-derive" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -8824,11 +8975,11 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "chrono", "fdlimit", - "futures 0.3.19", + "futures 0.3.21", "hex", "libp2p", "log", @@ -8847,10 +8998,10 @@ dependencies = [ "serde", "serde_json", "sp-blockchain", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-keyring", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-panic-handler 4.0.0-dev", + "sp-keystore 0.10.0", + "sp-panic-handler 4.0.0", "sp-runtime", "sp-version", "structopt", @@ -8862,10 +9013,10 @@ dependencies = [ [[package]] name = "sc-client-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "fnv", - "futures 0.3.19", + "futures 0.3.21", "hash-db", "log", "parity-scale-codec", @@ -8876,21 +9027,21 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-consensus", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-database", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-externalities 0.10.0", + "sp-keystore 0.10.0", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-storage 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", + "sp-storage 4.0.0", + "sp-trie 4.0.0", "substrate-prometheus-endpoint", ] [[package]] name = "sc-client-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "hash-db", "kvdb", @@ -8905,21 +9056,21 @@ dependencies = [ "sc-state-db", "sp-arithmetic", "sp-blockchain", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-database", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", + "sp-trie 4.0.0", ] [[package]] name = "sc-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "libp2p", "log", "parking_lot 0.11.2", @@ -8929,22 +9080,51 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-consensus", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", "substrate-prometheus-endpoint", "thiserror", ] +[[package]] +name = "sc-consensus-aura" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" +dependencies = [ + "async-trait", + "derive_more", + "futures 0.3.21", + "log", + "parity-scale-codec", + "sc-block-builder", + "sc-client-api", + "sc-consensus", + "sc-consensus-slots", + "sc-telemetry", + "sp-api", + "sp-application-crypto", + "sp-block-builder", + "sp-blockchain", + "sp-consensus", + "sp-consensus-aura", + "sp-consensus-slots", + "sp-core 4.1.0-dev", + "sp-inherents", + "sp-keystore 0.10.0", + "sp-runtime", + "substrate-prometheus-endpoint", +] + [[package]] name = "sc-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", "derive_more", "fork-tree", - "futures 0.3.19", + "futures 0.3.21", "log", "merlin", "num-bigint", @@ -8970,10 +9150,10 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-slots", "sp-consensus-vrf", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", + "sp-keystore 0.10.0", "sp-runtime", "sp-version", "substrate-prometheus-endpoint", @@ -8982,10 +9162,10 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "derive_more", - "futures 0.3.19", + "futures 0.3.21", "jsonrpc-core 18.0.0", "jsonrpc-core-client 18.0.0", "jsonrpc-derive 18.0.0", @@ -8998,15 +9178,15 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-babe", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-keystore 0.10.0", "sp-runtime", ] [[package]] name = "sc-consensus-epochs" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "fork-tree", "parity-scale-codec", @@ -9019,12 +9199,12 @@ dependencies = [ [[package]] name = "sc-consensus-manual-seal" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "assert_matches", "async-trait", "derive_more", - "futures 0.3.19", + "futures 0.3.21", "jsonrpc-core 18.0.0", "jsonrpc-core-client 18.0.0", "jsonrpc-derive 18.0.0", @@ -9032,6 +9212,7 @@ dependencies = [ "parity-scale-codec", "sc-client-api", "sc-consensus", + "sc-consensus-aura", "sc-consensus-babe", "sc-consensus-epochs", "sc-transaction-pool", @@ -9040,11 +9221,12 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-consensus", + "sp-consensus-aura", "sp-consensus-babe", "sp-consensus-slots", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-keystore 0.10.0", "sp-runtime", "sp-timestamp", "substrate-prometheus-endpoint", @@ -9053,25 +9235,24 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "log", "parity-scale-codec", "sc-client-api", "sc-consensus", "sc-telemetry", - "sp-api", "sp-arithmetic", "sp-blockchain", "sp-consensus", "sp-consensus-slots", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", "sp-timestamp", "thiserror", ] @@ -9079,7 +9260,7 @@ dependencies = [ [[package]] name = "sc-consensus-uncles" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "sc-client-api", "sp-authorship", @@ -9090,68 +9271,69 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "lazy_static", "libsecp256k1 0.7.0", "log", + "lru 0.6.6", "parity-scale-codec", "parking_lot 0.11.2", "sc-executor-common", "sc-executor-wasmi", "sc-executor-wasmtime", "sp-api", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-core-hashing-proc-macro", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-panic-handler 4.0.0-dev", - "sp-runtime-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-externalities 0.10.0", + "sp-io 4.0.0", + "sp-panic-handler 4.0.0", + "sp-runtime-interface 4.1.0-dev", "sp-tasks", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-trie 4.0.0", "sp-version", - "sp-wasm-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-wasm-interface 4.1.0-dev", "wasmi", ] [[package]] name = "sc-executor-common" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "derive_more", "environmental", "parity-scale-codec", - "pwasm-utils", "sc-allocator", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-maybe-compressed-blob", "sp-serializer", - "sp-wasm-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-wasm-interface 4.1.0-dev", "thiserror", + "wasm-instrument", "wasmi", ] [[package]] name = "sc-executor-wasmi" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "log", "parity-scale-codec", "sc-allocator", "sc-executor-common", "scoped-tls", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-runtime-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-wasm-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-runtime-interface 4.1.0-dev", + "sp-wasm-interface 4.1.0-dev", "wasmi", ] [[package]] name = "sc-executor-wasmtime" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "cfg-if 1.0.0", "libc", @@ -9160,29 +9342,30 @@ dependencies = [ "parity-wasm 0.42.2", "sc-allocator", "sc-executor-common", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-runtime-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-wasm-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-runtime-interface 4.1.0-dev", + "sp-wasm-interface 4.1.0-dev", "wasmtime", ] [[package]] name = "sc-finality-grandpa" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", "derive_more", "dyn-clone", "finality-grandpa", "fork-tree", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "log", "parity-scale-codec", "parking_lot 0.11.2", - "rand 0.8.4", + "rand 0.8.5", "sc-block-builder", + "sc-chain-spec", "sc-client-api", "sc-consensus", "sc-keystore", @@ -9196,9 +9379,9 @@ dependencies = [ "sp-arithmetic", "sp-blockchain", "sp-consensus", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-finality-grandpa", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-keystore 0.10.0", "sp-runtime", "substrate-prometheus-endpoint", ] @@ -9206,11 +9389,11 @@ dependencies = [ [[package]] name = "sc-finality-grandpa-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "derive_more", "finality-grandpa", - "futures 0.3.19", + "futures 0.3.21", "jsonrpc-core 18.0.0", "jsonrpc-core-client 18.0.0", "jsonrpc-derive 18.0.0", @@ -9223,18 +9406,18 @@ dependencies = [ "serde", "serde_json", "sp-blockchain", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", ] [[package]] name = "sc-informant" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "ansi_term", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "log", "parity-util-mem", "sc-client-api", @@ -9247,7 +9430,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", "derive_more", @@ -9255,14 +9438,14 @@ dependencies = [ "parking_lot 0.11.2", "serde_json", "sp-application-crypto", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-keystore 0.10.0", ] [[package]] name = "sc-network" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-std", "async-trait", @@ -9274,8 +9457,8 @@ dependencies = [ "either", "fnv", "fork-tree", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "hex", "ip_network", "libp2p", @@ -9300,7 +9483,7 @@ dependencies = [ "sp-arithmetic", "sp-blockchain", "sp-consensus", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-finality-grandpa", "sp-runtime", "substrate-prometheus-endpoint", @@ -9313,10 +9496,10 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "libp2p", "log", "lru 0.7.2", @@ -9329,12 +9512,12 @@ dependencies = [ [[package]] name = "sc-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "bytes 1.1.0", "fnv", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "hex", "hyper", "hyper-rustls", @@ -9347,7 +9530,7 @@ dependencies = [ "sc-network", "sc-utils", "sp-api", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-offchain", "sp-runtime", "threadpool", @@ -9357,9 +9540,9 @@ dependencies = [ [[package]] name = "sc-peerset" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "libp2p", "log", "sc-utils", @@ -9370,7 +9553,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -9379,9 +9562,9 @@ dependencies = [ [[package]] name = "sc-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "hash-db", "jsonrpc-core 18.0.0", "jsonrpc-pubsub 18.0.0", @@ -9398,8 +9581,8 @@ dependencies = [ "serde_json", "sp-api", "sp-blockchain", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-keystore 0.10.0", "sp-offchain", "sp-rpc", "sp-runtime", @@ -9410,9 +9593,9 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "jsonrpc-core 18.0.0", "jsonrpc-core-client 18.0.0", "jsonrpc-derive 18.0.0", @@ -9424,10 +9607,10 @@ dependencies = [ "sc-transaction-pool-api", "serde", "serde_json", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-rpc", "sp-runtime", - "sp-tracing 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-tracing 4.0.0", "sp-version", "thiserror", ] @@ -9435,9 +9618,9 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "jsonrpc-core 18.0.0", "jsonrpc-http-server", "jsonrpc-ipc-server", @@ -9452,13 +9635,13 @@ dependencies = [ [[package]] name = "sc-service" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", "directories", "exit-future", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "hash-db", "jsonrpc-core 18.0.0", "jsonrpc-pubsub 18.0.0", @@ -9492,18 +9675,18 @@ dependencies = [ "sp-block-builder", "sp-blockchain", "sp-consensus", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-externalities 0.10.0", "sp-inherents", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-keystore 0.10.0", "sp-runtime", "sp-session", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-storage 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-tracing 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", + "sp-storage 4.0.0", + "sp-tracing 4.0.0", "sp-transaction-pool", "sp-transaction-storage-proof", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-trie 4.0.0", "sp-version", "substrate-prometheus-endpoint", "tempfile", @@ -9516,7 +9699,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "log", "parity-scale-codec", @@ -9524,13 +9707,13 @@ dependencies = [ "parity-util-mem-derive", "parking_lot 0.11.2", "sc-client-api", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", ] [[package]] name = "sc-sync-state-rpc" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "jsonrpc-core 18.0.0", "jsonrpc-core-client 18.0.0", @@ -9552,10 +9735,10 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "chrono", - "futures 0.3.19", + "futures 0.3.21", "libp2p", "log", "parking_lot 0.11.2", @@ -9570,7 +9753,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "ansi_term", "atty", @@ -9588,10 +9771,10 @@ dependencies = [ "serde", "sp-api", "sp-blockchain", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-rpc", "sp-runtime", - "sp-tracing 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-tracing 4.0.0", "thiserror", "tracing", "tracing-log", @@ -9601,9 +9784,9 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -9612,10 +9795,10 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "futures 0.3.19", - "intervalier", + "futures 0.3.21", + "futures-timer", "linked-hash-map", "log", "parity-scale-codec", @@ -9628,9 +9811,9 @@ dependencies = [ "serde", "sp-api", "sp-blockchain", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-tracing 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-tracing 4.0.0", "sp-transaction-pool", "substrate-prometheus-endpoint", "thiserror", @@ -9639,10 +9822,10 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "derive_more", - "futures 0.3.19", + "futures 0.3.21", "log", "serde", "sp-blockchain", @@ -9653,11 +9836,12 @@ dependencies = [ [[package]] name = "sc-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "lazy_static", + "parking_lot 0.11.2", "prometheus", ] @@ -9681,7 +9865,7 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baeb2780690380592f86205aa4ee49815feb2acad8c2f59e6dd207148c3f1fcd" dependencies = [ - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -9757,9 +9941,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.6.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fed7948b6c68acbb6e20c334f55ad635dc0f75506963de4464289fbd3b051ac" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" dependencies = [ "bitflags", "core-foundation", @@ -9770,9 +9954,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.6.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a57321bf8bc2362081b2599912d2961fe899c0efadf1b4b2f8d48b3e253bb96c" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" dependencies = [ "core-foundation-sys", "libc", @@ -9807,9 +9991,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" +checksum = "0486718e92ec9a68fbed73bb5ef687d71103b142595b406835649bebd33f72c7" dependencies = [ "serde", ] @@ -9860,9 +10044,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d23c1ba4cf0efd44be32017709280b32d1cea5c3f1275c3b6d9e8bc54f758085" +checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" dependencies = [ "itoa 1.0.1", "ryu", @@ -9919,6 +10103,17 @@ dependencies = [ "opaque-debug 0.3.0", ] +[[package]] +name = "sha2" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99c3bd8169c58782adad9290a9af5939994036b76187f7b4f0e6de91dbbfc0ec" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures 0.2.1", + "digest 0.10.3", +] + [[package]] name = "sha3" version = "0.9.1" @@ -10020,14 +10215,14 @@ dependencies = [ [[package]] name = "slot-range-helper" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "enumn", "parity-scale-codec", "paste", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] @@ -10069,7 +10264,7 @@ dependencies = [ "aes-gcm", "blake2", "chacha20poly1305", - "rand 0.8.4", + "rand 0.8.5", "rand_core 0.6.3", "ring", "rustc_version 0.3.3", @@ -10108,26 +10303,26 @@ dependencies = [ "base64 0.13.0", "bytes 1.1.0", "flate2", - "futures 0.3.19", + "futures 0.3.21", "httparse", "log", - "rand 0.8.4", + "rand 0.8.5", "sha-1 0.9.8", ] [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "hash-db", "log", "parity-scale-codec", "sp-api-proc-macro", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", + "sp-std 4.0.0", "sp-version", "thiserror", ] @@ -10135,10 +10330,10 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "blake2-rfc", - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -10146,75 +10341,75 @@ dependencies = [ [[package]] name = "sp-application-crypto" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", + "sp-std 4.0.0", ] [[package]] name = "sp-arithmetic" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "integer-sqrt", "num-traits", "parity-scale-codec", "scale-info", "serde", - "sp-debug-derive 4.0.0-dev", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-debug-derive 4.0.0", + "sp-std 4.0.0", "static_assertions", ] [[package]] name = "sp-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", "scale-info", "sp-api", "sp-application-crypto", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "sp-authorship" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", "parity-scale-codec", "sp-inherents", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "sp-block-builder" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", "sp-api", "sp-inherents", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "sp-blockchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "log", "lru 0.7.2", "parity-scale-codec", @@ -10223,33 +10418,51 @@ dependencies = [ "sp-consensus", "sp-database", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", "thiserror", ] [[package]] name = "sp-consensus" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", - "futures 0.3.19", - "futures-timer 3.0.2", + "futures 0.3.21", + "futures-timer", "log", "parity-scale-codec", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", + "sp-std 4.0.0", "sp-version", "thiserror", ] +[[package]] +name = "sp-consensus-aura" +version = "0.10.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" +dependencies = [ + "async-trait", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-application-crypto", + "sp-consensus", + "sp-consensus-slots", + "sp-inherents", + "sp-runtime", + "sp-std 4.0.0", + "sp-timestamp", +] + [[package]] name = "sp-consensus-babe" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", "merlin", @@ -10261,18 +10474,18 @@ dependencies = [ "sp-consensus", "sp-consensus-slots", "sp-consensus-vrf", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-keystore 0.10.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "sp-timestamp", ] [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", "scale-info", @@ -10284,13 +10497,13 @@ dependencies = [ [[package]] name = "sp-consensus-vrf" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", "schnorrkel", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] @@ -10303,7 +10516,7 @@ dependencies = [ "byteorder", "dyn-clonable", "ed25519-dalek", - "futures 0.3.19", + "futures 0.3.21", "hash-db", "hash256-std-hasher", "hex", @@ -10325,10 +10538,10 @@ dependencies = [ "serde", "sha2 0.9.9", "sp-debug-derive 3.0.0", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-runtime-interface 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-storage 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", + "sp-externalities 0.10.0-dev", + "sp-runtime-interface 4.0.0-dev", + "sp-std 4.0.0-dev", + "sp-storage 4.0.0-dev", "substrate-bip39", "thiserror", "tiny-bip39", @@ -10340,8 +10553,8 @@ dependencies = [ [[package]] name = "sp-core" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.1.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "base58 0.2.0", "bitflags", @@ -10349,7 +10562,7 @@ dependencies = [ "byteorder", "dyn-clonable", "ed25519-dalek", - "futures 0.3.19", + "futures 0.3.21", "hash-db", "hash256-std-hasher", "hex", @@ -10369,13 +10582,13 @@ dependencies = [ "schnorrkel", "secrecy 0.8.0", "serde", - "sha2 0.9.9", + "sha2 0.10.1", "sp-core-hashing", - "sp-debug-derive 4.0.0-dev", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-runtime-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-storage 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-debug-derive 4.0.0", + "sp-externalities 0.10.0", + "sp-runtime-interface 4.1.0-dev", + "sp-std 4.0.0", + "sp-storage 4.0.0", "ss58-registry", "substrate-bip39", "thiserror", @@ -10388,13 +10601,13 @@ dependencies = [ [[package]] name = "sp-core-hashing" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "blake2-rfc", "byteorder", - "sha2 0.9.9", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sha2 0.10.1", + "sp-std 4.0.0", "tiny-keccak", "twox-hash", ] @@ -10402,7 +10615,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "proc-macro2", "quote", @@ -10413,7 +10626,7 @@ dependencies = [ [[package]] name = "sp-database" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "kvdb", "parking_lot 0.11.2", @@ -10431,8 +10644,8 @@ dependencies = [ [[package]] name = "sp-debug-derive" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "proc-macro2", "quote", @@ -10446,25 +10659,25 @@ source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11#57 dependencies = [ "environmental", "parity-scale-codec", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-storage 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", + "sp-std 4.0.0-dev", + "sp-storage 4.0.0-dev", ] [[package]] name = "sp-externalities" -version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "0.10.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "environmental", "parity-scale-codec", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-storage 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", + "sp-storage 4.0.0", ] [[package]] name = "sp-finality-grandpa" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "finality-grandpa", "log", @@ -10473,23 +10686,23 @@ dependencies = [ "serde", "sp-api", "sp-application-crypto", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-keystore 0.10.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", "impl-trait-for-tuples", "parity-scale-codec", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "thiserror", ] @@ -10498,58 +10711,58 @@ name = "sp-io" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11#57346f6b24875f8935280dba51fa8ab0a9ba1e39" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "hash-db", "libsecp256k1 0.6.0", "log", "parity-scale-codec", "parking_lot 0.11.2", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-runtime-interface 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-tracing 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-wasm-interface 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", + "sp-core 4.0.0-dev", + "sp-externalities 0.10.0-dev", + "sp-keystore 0.10.0-dev", + "sp-runtime-interface 4.0.0-dev", + "sp-state-machine 0.10.0-dev", + "sp-std 4.0.0-dev", + "sp-tracing 4.0.0-dev", + "sp-trie 4.0.0-dev", + "sp-wasm-interface 4.0.0-dev", "tracing", "tracing-core", ] [[package]] name = "sp-io" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "hash-db", "libsecp256k1 0.7.0", "log", "parity-scale-codec", "parking_lot 0.11.2", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-runtime-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-tracing 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-wasm-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-externalities 0.10.0", + "sp-keystore 0.10.0", + "sp-runtime-interface 4.1.0-dev", + "sp-state-machine 0.10.0", + "sp-std 4.0.0", + "sp-tracing 4.0.0", + "sp-trie 4.0.0", + "sp-wasm-interface 4.1.0-dev", "tracing", "tracing-core", ] [[package]] name = "sp-keyring" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.1.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "lazy_static", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", - "strum", + "strum 0.22.0", ] [[package]] @@ -10559,36 +10772,36 @@ source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11#57 dependencies = [ "async-trait", "derive_more", - "futures 0.3.19", + "futures 0.3.21", "merlin", "parity-scale-codec", "parking_lot 0.11.2", "schnorrkel", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", + "sp-core 4.0.0-dev", + "sp-externalities 0.10.0-dev", ] [[package]] name = "sp-keystore" -version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "0.10.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", "derive_more", - "futures 0.3.19", + "futures 0.3.21", "merlin", "parity-scale-codec", "parking_lot 0.11.2", "schnorrkel", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-externalities 0.10.0", ] [[package]] name = "sp-maybe-compressed-blob" version = "4.1.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "zstd", ] @@ -10603,7 +10816,7 @@ dependencies = [ "bcs 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "bcs 0.1.3 (git+https://github.com/pontem-network/sp-move-vm.git?rev=c8ac6f91c7ec95e62afa3ee9ef9884eec113511c)", "constants", - "env_logger 0.9.0", + "env_logger", "frame-benchmarking", "frame-support", "frame-system", @@ -10626,10 +10839,10 @@ dependencies = [ "primitives", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "test-log", ] @@ -10661,30 +10874,30 @@ dependencies = [ "sp-api", "sp-mvm", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "sp-npos-elections" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", "scale-info", "serde", "sp-arithmetic", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-npos-elections-solution-type", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "sp-npos-elections-solution-type" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -10693,10 +10906,10 @@ dependencies = [ [[package]] name = "sp-offchain" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "sp-api", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", ] @@ -10710,8 +10923,8 @@ dependencies = [ [[package]] name = "sp-panic-handler" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "backtrace", "lazy_static", @@ -10721,17 +10934,17 @@ dependencies = [ [[package]] name = "sp-rpc" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "rustc-hash", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", ] [[package]] name = "sp-runtime" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.1.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "either", "hash256-std-hasher", @@ -10745,9 +10958,9 @@ dependencies = [ "serde", "sp-application-crypto", "sp-arithmetic", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", + "sp-std 4.0.0", ] [[package]] @@ -10758,29 +10971,29 @@ dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", "primitive-types 0.10.1", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-runtime-interface-proc-macro 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-storage 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-tracing 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-wasm-interface 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", + "sp-externalities 0.10.0-dev", + "sp-runtime-interface-proc-macro 4.0.0-dev", + "sp-std 4.0.0-dev", + "sp-storage 4.0.0-dev", + "sp-tracing 4.0.0-dev", + "sp-wasm-interface 4.0.0-dev", "static_assertions", ] [[package]] name = "sp-runtime-interface" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.1.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", "primitive-types 0.10.1", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-runtime-interface-proc-macro 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-storage 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-tracing 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-wasm-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-externalities 0.10.0", + "sp-runtime-interface-proc-macro 4.0.0", + "sp-std 4.0.0", + "sp-storage 4.0.0", + "sp-tracing 4.0.0", + "sp-wasm-interface 4.1.0-dev", "static_assertions", ] @@ -10790,7 +11003,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11#57346f6b24875f8935280dba51fa8ab0a9ba1e39" dependencies = [ "Inflector", - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -10798,11 +11011,11 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "Inflector", - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.1.2", "proc-macro2", "quote", "syn", @@ -10811,7 +11024,7 @@ dependencies = [ [[package]] name = "sp-serializer" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "serde", "serde_json", @@ -10820,26 +11033,26 @@ dependencies = [ [[package]] name = "sp-session" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", "scale-info", "sp-api", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", "scale-info", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] @@ -10854,21 +11067,21 @@ dependencies = [ "parking_lot 0.11.2", "rand 0.7.3", "smallvec 1.8.0", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", + "sp-core 4.0.0-dev", + "sp-externalities 0.10.0-dev", "sp-panic-handler 3.0.0", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", + "sp-std 4.0.0-dev", + "sp-trie 4.0.0-dev", "thiserror", "tracing", - "trie-db", - "trie-root", + "trie-db 0.22.6", + "trie-root 0.16.0", ] [[package]] name = "sp-state-machine" -version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "0.10.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "hash-db", "log", @@ -10877,15 +11090,15 @@ dependencies = [ "parking_lot 0.11.2", "rand 0.7.3", "smallvec 1.8.0", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-panic-handler 4.0.0-dev", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-externalities 0.10.0", + "sp-panic-handler 4.0.0", + "sp-std 4.0.0", + "sp-trie 4.0.0", "thiserror", "tracing", - "trie-db", - "trie-root", + "trie-db 0.23.1", + "trie-root 0.17.0", ] [[package]] @@ -10895,8 +11108,8 @@ source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11#57 [[package]] name = "sp-std" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" [[package]] name = "sp-storage" @@ -10908,48 +11121,48 @@ dependencies = [ "ref-cast", "serde", "sp-debug-derive 3.0.0", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", + "sp-std 4.0.0-dev", ] [[package]] name = "sp-storage" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "impl-serde", "parity-scale-codec", "ref-cast", "serde", - "sp-debug-derive 4.0.0-dev", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-debug-derive 4.0.0", + "sp-std 4.0.0", ] [[package]] name = "sp-tasks" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "log", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-runtime-interface 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-externalities 0.10.0", + "sp-io 4.0.0", + "sp-runtime-interface 4.1.0-dev", + "sp-std 4.0.0", ] [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", - "futures-timer 3.0.2", + "futures-timer", "log", "parity-scale-codec", "sp-api", "sp-inherents", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "thiserror", ] @@ -10965,7 +11178,7 @@ dependencies = [ "serde", "serde_json", "slog", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", + "sp-std 4.0.0-dev", "tracing", "tracing-core", "tracing-subscriber", @@ -10973,11 +11186,11 @@ dependencies = [ [[package]] name = "sp-tracing" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "tracing", "tracing-core", "tracing-subscriber", @@ -10986,7 +11199,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "sp-api", "sp-runtime", @@ -10995,17 +11208,17 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-trait", "log", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-trie 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", + "sp-trie 4.0.0", ] [[package]] @@ -11014,42 +11227,43 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11#57346f6b24875f8935280dba51fa8ab0a9ba1e39" dependencies = [ "hash-db", - "memory-db", + "memory-db 0.27.0", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", - "trie-db", - "trie-root", + "sp-core 4.0.0-dev", + "sp-std 4.0.0-dev", + "trie-db 0.22.6", + "trie-root 0.16.0", ] [[package]] name = "sp-trie" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.0.0" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "hash-db", - "memory-db", + "memory-db 0.28.0", "parity-scale-codec", "scale-info", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "trie-db", - "trie-root", + "sp-core 4.1.0-dev", + "sp-std 4.0.0", + "trie-db 0.23.1", + "trie-root 0.17.0", ] [[package]] name = "sp-version" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "impl-serde", "parity-scale-codec", "parity-wasm 0.42.2", "scale-info", "serde", + "sp-core-hashing-proc-macro", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "sp-version-proc-macro", "thiserror", ] @@ -11057,7 +11271,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -11072,19 +11286,21 @@ source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11#57 dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.11)", + "sp-std 4.0.0-dev", "wasmi", ] [[package]] name = "sp-wasm-interface" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +version = "4.1.0-dev" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "impl-trait-for-tuples", + "log", "parity-scale-codec", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "wasmi", + "wasmtime", ] [[package]] @@ -11093,11 +11309,20 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "spin" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5" +dependencies = [ + "lock_api 0.4.6", +] + [[package]] name = "ss58-registry" -version = "1.12.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8319f44e20b42e5c11b88b1ad4130c35fe2974665a007b08b02322070177136a" +checksum = "d8cb4b9ce18beb6cb16ecad62d936245cef5212ddc8e094d7417a75e8d0e85f5" dependencies = [ "Inflector", "proc-macro2", @@ -11154,7 +11379,7 @@ dependencies = [ "lazy_static", "nalgebra", "num-traits", - "rand 0.8.4", + "rand 0.8.5", ] [[package]] @@ -11205,7 +11430,16 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7ac893c7d471c8a21f31cfe213ec4f6d9afeed25537c772e08ef3f005f8729e" dependencies = [ - "strum_macros", + "strum_macros 0.22.0", +] + +[[package]] +name = "strum" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cae14b91c7d11c9a851d3fbc80a963198998c2a64eec840477fa92d8ce9b70bb" +dependencies = [ + "strum_macros 0.23.1", ] [[package]] @@ -11220,6 +11454,19 @@ dependencies = [ "syn", ] +[[package]] +name = "strum_macros" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bb0dc7ee9c15cea6199cde9a127fa16a4c5819af85395457ad72d68edc85a38" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "substrate-bip39" version = "0.4.4" @@ -11236,7 +11483,7 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "platforms", ] @@ -11254,10 +11501,10 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "frame-system-rpc-runtime-api", - "futures 0.3.19", + "futures 0.3.21", "jsonrpc-core 18.0.0", "jsonrpc-core-client 18.0.0", "jsonrpc-derive 18.0.0", @@ -11269,14 +11516,14 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-blockchain", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-runtime", ] [[package]] name = "substrate-prometheus-endpoint" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "async-std", "derive_more", @@ -11290,7 +11537,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "5.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "ansi_term", "build-helper", @@ -11638,9 +11885,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", @@ -11684,10 +11931,10 @@ dependencies = [ "primitives", "scale-info", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", ] [[package]] @@ -11703,6 +11950,19 @@ dependencies = [ "smallvec 1.8.0", ] +[[package]] +name = "trie-db" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32d034c0d3db64b43c31de38e945f15b40cd4ca6d2dcfc26d4798ce8de4ab83" +dependencies = [ + "hash-db", + "hashbrown 0.12.0", + "log", + "rustc-hex", + "smallvec 1.8.0", +] + [[package]] name = "trie-root" version = "0.16.0" @@ -11712,6 +11972,15 @@ dependencies = [ "hash-db", ] +[[package]] +name = "trie-root" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a36c5ca3911ed3c9a5416ee6c679042064b93fc637ded67e25f92e68d783891" +dependencies = [ + "hash-db", +] + [[package]] name = "trust-dns-proto" version = "0.20.4" @@ -11729,7 +11998,7 @@ dependencies = [ "ipnet", "lazy_static", "log", - "rand 0.8.4", + "rand 0.8.5", "smallvec 1.8.0", "thiserror", "tinyvec", @@ -11764,7 +12033,7 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "try-runtime-cli" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13#afb74de23dfe2994e7ce38c0870efb9734e966f7" +source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.16#4aeb95f7f38fcd519e2628f32f79044a8fef99d5" dependencies = [ "jsonrpsee", "log", @@ -11775,14 +12044,15 @@ dependencies = [ "sc-executor", "sc-service", "serde", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-externalities 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-keystore 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-externalities 0.10.0", + "sp-io 4.0.0", + "sp-keystore 0.10.0", "sp-runtime", - "sp-state-machine 0.10.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-state-machine 0.10.0", "sp-version", "structopt", + "zstd", ] [[package]] @@ -11798,7 +12068,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ee73e6e4924fe940354b8d4d98cad5231175d615cd855b758adc658c0aac6a0" dependencies = [ "cfg-if 1.0.0", - "rand 0.8.4", + "rand 0.8.5", "static_assertions", ] @@ -11825,9 +12095,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" [[package]] name = "uint" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1b413ebfe8c2c74a69ff124699dd156a7fa41cb1d09ba6df94aa2f2b0a4a3a" +checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0" dependencies = [ "byteorder", "crunchy", @@ -11861,9 +12131,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" +checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" [[package]] name = "unicode-width" @@ -12112,13 +12382,22 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "wasm-instrument" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "962e5b0401bbb6c887f54e69b8c496ea36f704df65db73e81fd5ff8dc3e63a9f" +dependencies = [ + "parity-wasm 0.42.2", +] + [[package]] name = "wasm-timer" version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "js-sys", "parking_lot 0.11.2", "pin-utils", @@ -12159,9 +12438,9 @@ checksum = "98930446519f63d00a836efdc22f67766ceae8dbcc1571379f2bcabc6b2b9abc" [[package]] name = "wasmtime" -version = "0.31.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "311d06b0c49346d1fbf48a17052e844036b95a7753c1afb34e8c0af3f6b5bb13" +checksum = "414be1bc5ca12e755ffd3ff7acc3a6d1979922f8237fc34068b2156cebcc3270" dependencies = [ "anyhow", "backtrace", @@ -12191,9 +12470,9 @@ dependencies = [ [[package]] name = "wasmtime-cache" -version = "0.31.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36147930a4995137dc096e5b17a573b446799be2bbaea433e821ce6a80abe2c5" +checksum = "8b9b4cd1949206fda9241faf8c460a7d797aa1692594d3dd6bc1cbfa57ee20d0" dependencies = [ "anyhow", "base64 0.13.0", @@ -12201,7 +12480,7 @@ dependencies = [ "directories-next", "file-per-thread-logger", "log", - "rsix", + "rustix", "serde", "sha2 0.9.9", "toml", @@ -12211,9 +12490,9 @@ dependencies = [ [[package]] name = "wasmtime-cranelift" -version = "0.31.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab3083a47e1ede38aac06a1d9831640d673f9aeda0b82a64e4ce002f3432e2e7" +checksum = "a4693d33725773615a4c9957e4aa731af57b27dca579702d1d8ed5750760f1a9" dependencies = [ "anyhow", "cranelift-codegen", @@ -12221,7 +12500,7 @@ dependencies = [ "cranelift-frontend", "cranelift-native", "cranelift-wasm", - "gimli 0.25.0", + "gimli", "log", "more-asserts", "object", @@ -12233,14 +12512,13 @@ dependencies = [ [[package]] name = "wasmtime-environ" -version = "0.31.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c2d194b655321053bc4111a1aa4ead552655c8a17d17264bc97766e70073510" +checksum = "5b17e47116a078b9770e6fb86cff8b9a660826623cebcfff251b047c8d8993ef" dependencies = [ "anyhow", - "cfg-if 1.0.0", "cranelift-entity", - "gimli 0.25.0", + "gimli", "indexmap 1.8.0", "log", "more-asserts", @@ -12254,24 +12532,21 @@ dependencies = [ [[package]] name = "wasmtime-jit" -version = "0.31.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864ac8dfe4ce310ac59f16fdbd560c257389cb009ee5d030ac6e30523b023d11" +checksum = "60ea5b380bdf92e32911400375aeefb900ac9d3f8e350bb6ba555a39315f2ee7" dependencies = [ - "addr2line 0.16.0", + "addr2line", "anyhow", "bincode", "cfg-if 1.0.0", - "gimli 0.25.0", - "log", - "more-asserts", + "gimli", "object", "region", - "rsix", + "rustix", "serde", "target-lexicon", "thiserror", - "wasmparser", "wasmtime-environ", "wasmtime-runtime", "winapi 0.3.9", @@ -12279,9 +12554,9 @@ dependencies = [ [[package]] name = "wasmtime-runtime" -version = "0.31.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab97da813a26b98c9abfd3b0c2d99e42f6b78b749c0646344e2e262d212d8c8b" +checksum = "abc7cd79937edd6e238b337608ebbcaf9c086a8457f01dfd598324f7fa56d81a" dependencies = [ "anyhow", "backtrace", @@ -12294,9 +12569,9 @@ dependencies = [ "mach", "memoffset", "more-asserts", - "rand 0.8.4", + "rand 0.8.5", "region", - "rsix", + "rustix", "thiserror", "wasmtime-environ", "winapi 0.3.9", @@ -12304,9 +12579,9 @@ dependencies = [ [[package]] name = "wasmtime-types" -version = "0.31.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff94409cc3557bfbbcce6b14520ccd6bd3727e965c0fe68d63ef2c185bf379c6" +checksum = "d9e5e51a461a2cf2b69e1fc48f325b17d78a8582816e18479e8ead58844b23f8" dependencies = [ "cranelift-entity", "serde", @@ -12354,8 +12629,8 @@ dependencies = [ [[package]] name = "westend-runtime" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "beefy-primitives", "bitvec", @@ -12388,6 +12663,7 @@ dependencies = [ "pallet-nicks", "pallet-offences", "pallet-offences-benchmarking", + "pallet-preimage", "pallet-proxy", "pallet-recovery", "pallet-scheduler", @@ -12419,23 +12695,36 @@ dependencies = [ "sp-authority-discovery", "sp-block-builder", "sp-consensus-babe", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", "sp-inherents", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-npos-elections", "sp-offchain", "sp-runtime", "sp-session", "sp-staking", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "sp-transaction-pool", "sp-version", "substrate-wasm-builder", + "westend-runtime-constants", "xcm", "xcm-builder", "xcm-executor", ] +[[package]] +name = "westend-runtime-constants" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" +dependencies = [ + "frame-support", + "polkadot-primitives", + "polkadot-runtime-common", + "smallvec 1.8.0", + "sp-runtime", +] + [[package]] name = "which" version = "4.2.4" @@ -12534,8 +12823,8 @@ dependencies = [ [[package]] name = "xcm" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "derivative", "impl-trait-for-tuples", @@ -12547,8 +12836,8 @@ dependencies = [ [[package]] name = "xcm-builder" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "frame-support", "frame-system", @@ -12558,9 +12847,9 @@ dependencies = [ "polkadot-parachain", "scale-info", "sp-arithmetic", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", "xcm-executor", ] @@ -12568,7 +12857,7 @@ dependencies = [ [[package]] name = "xcm-emulator" version = "0.1.0" -source = "git+https://github.com/pontem-network/xcm-simulator?branch=polkadot-v0.9.13#0e6af33b4da4766bb098d06b00ef85a26c06b24f" +source = "git+https://github.com/pontem-network/xcm-simulator?branch=polkadot-v0.9.16#b91b7420bbd0337794e9295f7ca203afcdd16c8b" dependencies = [ "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", @@ -12583,16 +12872,16 @@ dependencies = [ "paste", "polkadot-primitives", "polkadot-runtime-parachains", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-io 4.0.0", + "sp-std 4.0.0", "xcm", "xcm-executor", ] [[package]] name = "xcm-executor" -version = "0.9.13" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +version = "0.9.16" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ "frame-benchmarking", "frame-support", @@ -12600,18 +12889,19 @@ dependencies = [ "log", "parity-scale-codec", "sp-arithmetic", - "sp-core 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", - "sp-io 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-core 4.1.0-dev", + "sp-io 4.0.0", "sp-runtime", - "sp-std 4.0.0-dev (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.13)", + "sp-std 4.0.0", "xcm", ] [[package]] name = "xcm-procedural" version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.13#7d8f00b90cd6d87780123b3e08ca120cfb0c6e50" +source = "git+https://github.com/paritytech/polkadot.git?branch=release-v0.9.16#41ab002d7451766324a9f314fee11c9c53314350" dependencies = [ + "Inflector", "proc-macro2", "quote", "syn", @@ -12623,11 +12913,11 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7d9028f208dd5e63c614be69f115c1b53cacc1111437d4c765185856666c107" dependencies = [ - "futures 0.3.19", + "futures 0.3.21", "log", "nohash-hasher", "parking_lot 0.11.2", - "rand 0.8.4", + "rand 0.8.5", "static_assertions", ] diff --git a/README.md b/README.md index 230d7924..b814a6c2 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ There are several options to launch Pontem local parachain: Install [polkadot-launch](https://github.com/paritytech/polkadot-launch). -**Note:** you must have polkadot node `v0.9.13` compiled and built placed in `../polkadot/target/release/`. +**Note:** you must have polkadot node `v0.9.16` compiled and built placed in `../polkadot/target/release/`. To use different localion you can modify `./launch-config.json`. Create keystore path for Pontem: @@ -105,7 +105,7 @@ Build Polkadot: git clone https://github.com/paritytech/polkadot.git cd polkadot git fetch origin -git checkout release-v0.9.13 +git checkout release-v0.9.16 cargo build --release ``` diff --git a/docker-compose.yml b/docker-compose.yml index dfe666b8..816061f0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: dockerfile: launch.Dockerfile args: PONTEM_VERSION: v0.4.1 - POLKADOT_VERSION: v0.9.13 + POLKADOT_VERSION: v0.9.16 NODE_VERSION: 16 ports: - "9944:9944" # Alice relaychain diff --git a/node/Cargo.toml b/node/Cargo.toml index f14d7329..c9b1052a 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -17,7 +17,7 @@ path = "src/main.rs" targets = ['x86_64-unknown-linux-gnu'] [build-dependencies] -substrate-build-script-utils = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +substrate-build-script-utils = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } stdlib-fetch = { path = "../utils/stdlib-fetch" } [dependencies] @@ -26,68 +26,72 @@ futures = { version = "0.3.1", features = ["compat"] } jsonrpc-core = '18.0' serde_json = '1.0' structopt = '0.3.8' -codec = { package = 'parity-scale-codec', version = '2.3.0' } +codec = { package = 'parity-scale-codec', version = '2.3.1' } log = "0.4" serde = { version = "1.0", features = ["derive"] } # Substrate dependencies -frame-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +frame-benchmarking = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +frame-benchmarking-cli = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-transaction-payment-rpc = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +substrate-frame-rpc-system = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +substrate-prometheus-endpoint = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } # Substarte Client Dependencies -sc-basic-authorship = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-cli = { git = "https://github.com/paritytech/substrate.git", branch = 'polkadot-v0.9.13', features = ['wasmtime'] } -sc-client-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-executor = { git = "https://github.com/paritytech/substrate.git", branch = 'polkadot-v0.9.13', features = ['wasmtime'] } -sc-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-keystore = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-rpc-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-service = { git = "https://github.com/paritytech/substrate.git", branch = 'polkadot-v0.9.13', features = ['wasmtime'] } -sc-telemetry = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-transaction-pool = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-tracing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-chain-spec = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-network = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sc-consensus-manual-seal = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +sc-basic-authorship = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-cli = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16', features = ['wasmtime'] } +sc-client-api = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-consensus = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-executor = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16', features = ['wasmtime'] } +sc-finality-grandpa = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-keystore = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-rpc = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-rpc-api = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-service = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16', features = ['wasmtime'] } +sc-telemetry = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-transaction-pool = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-tracing = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-chain-spec = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-network = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-transaction-pool-api = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sc-consensus-manual-seal = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } # Substrate Primitive Dependencies -sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-blockchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-consensus = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-inherents = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-transaction-pool = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-timestamp = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-session = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-offchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-keystore = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +sp-api = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-block-builder = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-blockchain = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-consensus = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-finality-grandpa = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-inherents = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-transaction-pool = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-timestamp = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-session = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-offchain = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-keystore = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } # Nimbus dependencies -nimbus-primitives = { git = "https://github.com/pontem-network/nimbus.git", branch = "polkadot-v0.9.13" } -nimbus-consensus = { git = "https://github.com/pontem-network/nimbus.git", branch = "polkadot-v0.9.13" } +nimbus-primitives = { git = "https://github.com/pontem-network/nimbus", branch = 'polkadot-v0.9.16' } +nimbus-consensus = { git = "https://github.com/pontem-network/nimbus", branch = 'polkadot-v0.9.16' } # Cumulus dependencies -cumulus-client-consensus-relay-chain = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-client-network = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-client-service = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-client-cli = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } +cumulus-client-consensus-relay-chain = { git = "https://github.com/paritytech/cumulus", branch = 'polkadot-v0.9.16' } +cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus", branch = 'polkadot-v0.9.16' } +cumulus-client-network = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-client-service = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-client-cli = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-primitives-core = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-primitives-parachain-inherent = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-relay-chain-local = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-relay-chain-interface = { git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } # Polkadot dependencies -polkadot-primitives = { git = "https://github.com/paritytech/polkadot.git", branch = "release-v0.9.13" } -polkadot-service = { git = "https://github.com/paritytech/polkadot.git", branch = "release-v0.9.13" } -polkadot-parachain = { git = "https://github.com/paritytech/polkadot.git", branch = "release-v0.9.13" } +polkadot-primitives = { git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.16' } +polkadot-service = { git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.16' } +polkadot-parachain = { git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.16' } + +flume = "0.10.9" # Local dependencies pontem-runtime = { path = "../runtime" } @@ -105,8 +109,7 @@ constants = { path = "../constants" } # # ** Don't enable relay chains you don't need, as this is a **very** heavy build for no reason** # More info: https://github.com/paritytech/polkadot/pull/3189 - -polkadot-cli = { git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.13', features = ["kusama-native"] } +polkadot-cli = { git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.16', features = ["kusama-native"] } [dependencies.move-vm] package = "mvm" diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index b1c4ba76..a93eb19d 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -10,7 +10,7 @@ use pontem_runtime::{ GenesisConfig, SudoConfig, SystemConfig, BalancesConfig, WASM_BINARY, ParachainInfoConfig, VestingConfig, MvmConfig, TransactionPauseConfig, ParachainStakingConfig, InflationInfo, Range, AuthorFilterConfig, AuthorMappingConfig, TreasuryConfig, TokensConfig, - DemocracyConfig, PolkadotXcmConfig, SchedulerConfig, + DemocracyConfig, PolkadotXcmConfig, }; use primitives::{currency::CurrencyId, AccountId, Signature, Balance, BlockNumber}; use constants::SS58_PREFIX; @@ -152,7 +152,7 @@ fn paused_extrinsics() -> Vec<(Vec, Vec)> { "teleport_assets", ], ), - ("ParachainStaking", vec!["join_candidates", "nominate"]), + ("ParachainStaking", vec!["join_candidates", "delegate"]), ("Treasury", vec!["propose_spend"]), ("Mvm", vec!["execute", "publish_module", "publish_package"]), ( @@ -246,6 +246,8 @@ pub fn development_config() -> Result { None, // Protocol ID None, + // Fork ID + None, // Properties properties(), // Extensions @@ -334,6 +336,8 @@ pub fn local_testnet_config() -> Result { None, // Protocol ID Some("pontem_testnet"), + // Fork ID + None, // Properties properties(), // Extensions @@ -465,6 +469,8 @@ pub fn westend_config() -> Result { None, // Protocol ID Some("nox_westend"), + // Fork ID + None, // Properties properties(), // Extensions @@ -709,6 +715,8 @@ pub fn nox_config() -> Result { None, // Protocol ID Some("nox_mainnet"), + // Fork ID + None, // Properties properties(), // Extensions @@ -724,7 +732,7 @@ fn genesis( wasm_binary: &[u8], root_key: AccountId, candidates: Vec<(AccountId, NimbusId, Balance)>, - nominations: Vec<(AccountId, AccountId, Balance)>, + delegations: Vec<(AccountId, AccountId, Balance)>, balances: Vec<(AccountId, Balance)>, vesting: Vec<(AccountId, BlockNumber, BlockNumber, Balance)>, paused: Vec<(Vec, Vec)>, @@ -754,7 +762,7 @@ fn genesis( parachain_info: ParachainInfoConfig { parachain_id: id }, sudo: SudoConfig { // Assign network admin rights. - key: root_key, + key: Some(root_key), }, parachain_staking: ParachainStakingConfig { candidates: candidates @@ -762,7 +770,7 @@ fn genesis( .cloned() .map(|(account, _, bond)| (account, bond)) .collect(), - nominations, + delegations, inflation_config: pontem_inflation_config(), }, author_filter: AuthorFilterConfig { @@ -790,7 +798,6 @@ fn genesis( vesting: VestingConfig { vesting }, treasury: TreasuryConfig {}, democracy: DemocracyConfig::default(), - scheduler: SchedulerConfig {}, } } diff --git a/node/src/command.rs b/node/src/command.rs index 64d74249..c528736e 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -207,8 +207,11 @@ pub fn run() -> sc_cli::Result<()> { builder.with_profiling(sc_tracing::TracingReceiver::Log, ""); let _ = builder.init(); - let block: Block = - generate_genesis_block(&load_spec(¶ms.chain.clone().unwrap_or_default())?)?; + let chain_spec = load_spec(¶ms.chain.clone().unwrap_or_default())?; + + let state_version = Cli::native_runtime_version(&chain_spec).state_version(); + + let block: Block = generate_genesis_block(&chain_spec, state_version)?; let raw_header = block.header().encode(); let output_buf = if params.raw { raw_header @@ -264,8 +267,11 @@ pub fn run() -> sc_cli::Result<()> { let parachain_account = AccountIdConversion::::into_account(&id); - let block: Block = - generate_genesis_block(&config.chain_spec).map_err(|e| format!("{:?}", e))?; + let state_version = + Cli::native_runtime_version(&config.chain_spec).state_version(); + + let block: Block = generate_genesis_block(&config.chain_spec, state_version) + .map_err(|e| format!("{:?}", e))?; let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode())); let task_executor = config.tokio_handle.clone(); @@ -348,11 +354,26 @@ impl sc_cli::CliConfiguration for RelayChainCli { self.base.base.rpc_ws(default_listen_port) } - fn prometheus_config(&self, default_listen_port: u16) -> Result> { - self.base.base.prometheus_config(default_listen_port) + fn prometheus_config( + &self, + default_listen_port: u16, + chain_spec: &Box, + ) -> Result> { + self.base + .base + .prometheus_config(default_listen_port, chain_spec) } - fn init(&self) -> Result<()> { + fn init( + &self, + _support_url: &String, + _impl_version: &String, + _logger_hook: F, + _config: &sc_service::Configuration, + ) -> Result<()> + where + F: FnOnce(&mut sc_cli::LoggerBuilder, &sc_service::Configuration), + { unreachable!("PolkadotCli is never initialized; qed"); } diff --git a/node/src/service.rs b/node/src/service.rs index 0dfa41a6..16a5bbfc 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -1,13 +1,15 @@ -use cumulus_client_network::build_block_announce_validator; +use cumulus_relay_chain_local::build_relay_chain_interface; use crate::cli::Sealing; -use cumulus_primitives_parachain_inherent::MockValidationDataInherentDataProvider; +use cumulus_primitives_parachain_inherent::{MockValidationDataInherentDataProvider, MockXcmConfig}; use futures::StreamExt; use sp_core::H256; use cumulus_client_service::{ prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams, }; +use std::time::Duration; use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams}; +use cumulus_relay_chain_interface::RelayChainInterface; use cumulus_primitives_core::ParaId; use pontem_runtime::RuntimeApi; use sp_blockchain::HeaderBackend; @@ -17,10 +19,14 @@ use std::sync::Arc; use substrate_prometheus_endpoint::Registry; use sp_keystore::SyncCryptoStorePtr; use cumulus_client_consensus_common::ParachainConsensus; +use cumulus_client_network::BlockAnnounceValidator; use nimbus_primitives::NimbusId; -use nimbus_consensus::{build_nimbus_consensus, BuildNimbusConsensusParams}; +use nimbus_consensus::{ + BuildNimbusConsensusParams, NimbusConsensus, NimbusManualSealConsensusDataProvider, +}; use primitives::Block; use sc_executor::NativeElseWasmExecutor; +use sp_runtime::Percent; type FullBackend = TFullBackend; type FullClient = @@ -76,6 +82,7 @@ pub fn new_partial( config.wasm_method, config.default_heap_pages, config.max_runtime_instances, + config.runtime_cache_size, ); let (client, backend, keystore_container, task_manager) = @@ -122,6 +129,7 @@ pub fn new_partial( }, &task_manager.spawn_essential_handle(), config.prometheus_registry().clone(), + !dev_service, )? }; @@ -162,30 +170,24 @@ async fn start_node_impl( let params = new_partial(¶chain_config, false)?; let (mut telemetry, telemetry_worker_handle) = params.other; + let mut task_manager = params.task_manager; - let relay_chain_full_node = cumulus_client_service::build_polkadot_full_node( - polkadot_config, - telemetry_worker_handle, - ) - .map_err(|e| match e { - polkadot_service::Error::Sub(x) => x, - s => format!("{}", s).into(), - })?; + let (relay_chain_full_node, collator_key) = + build_relay_chain_interface(polkadot_config, telemetry_worker_handle, &mut task_manager) + .map_err(|e| match e { + polkadot_service::Error::Sub(x) => x, + s => format!("{}", s).into(), + })?; let client = params.client.clone(); let backend = params.backend.clone(); - let block_announce_validator = build_block_announce_validator( - relay_chain_full_node.client.clone(), - id, - Box::new(relay_chain_full_node.network.clone()), - relay_chain_full_node.backend.clone(), - ); + + let block_announce_validator = BlockAnnounceValidator::new(relay_chain_full_node.clone(), id); let is_validator = parachain_config.role.is_authority(); let force_authoring = parachain_config.force_authoring; let prometheus_registry = parachain_config.prometheus_registry().cloned(); let transaction_pool = params.transaction_pool.clone(); - let mut task_manager = params.task_manager; let import_queue = cumulus_client_service::SharedImportQueue::new(params.import_queue); let (network, system_rpc_tx, start_network) = sc_service::build_network(sc_service::BuildNetworkParams { @@ -195,7 +197,9 @@ async fn start_node_impl( spawn_handle: task_manager.spawn_handle(), import_queue: import_queue.clone(), warp_sync: None, - block_announce_validator_builder: Some(Box::new(|_| block_announce_validator)), + block_announce_validator_builder: Some(Box::new(|_| { + Box::new(block_announce_validator) + })), })?; let rpc_extensions_builder = { @@ -232,6 +236,8 @@ async fn start_node_impl( Arc::new(move |hash, data| network.announce_block(hash, data)) }; + let relay_chain_slot_duration = Duration::from_secs(6); + if is_validator { let parachain_consensus = build_consensus( id, @@ -239,7 +245,7 @@ async fn start_node_impl( prometheus_registry.as_ref(), telemetry.as_ref().map(|t| t.handle()), &task_manager, - &relay_chain_full_node, + relay_chain_full_node.clone(), transaction_pool, params.keystore_container.sync_keystore(), force_authoring, @@ -251,10 +257,12 @@ async fn start_node_impl( announce_block, client: client.clone(), task_manager: &mut task_manager, - relay_chain_full_node, + relay_chain_interface: relay_chain_full_node, spawner, parachain_consensus, import_queue, + collator_key, + relay_chain_slot_duration, }; start_collator(params).await?; @@ -264,7 +272,9 @@ async fn start_node_impl( announce_block, task_manager: &mut task_manager, para_id: id, - relay_chain_full_node, + relay_chain_interface: relay_chain_full_node, + relay_chain_slot_duration, + import_queue, }; start_full_node(params)?; @@ -281,32 +291,32 @@ fn build_consensus( prometheus_registry: Option<&Registry>, telemetry: Option, task_manager: &TaskManager, - relay_chain_node: &polkadot_service::NewFull, + relay_chain_node: Arc, transaction_pool: Arc>, keystore: SyncCryptoStorePtr, force_authoring: bool, ) -> Result>, sc_service::Error> { - let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( + let mut proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording( task_manager.spawn_handle(), client.clone(), transaction_pool, prometheus_registry.clone(), telemetry.clone(), ); - - let relay_chain_backend = relay_chain_node.backend.clone(); - let relay_chain_client = relay_chain_node.client.clone(); + proposer_factory.set_soft_deadline(Percent::from_percent(100)); let create_inherent_data_providers = move |_, (relay_parent, validation_data, author_id)| { - let parachain_inherent = - cumulus_primitives_parachain_inherent::ParachainInherentData::create_at_with_client( - relay_parent, - &relay_chain_client, - &*relay_chain_backend, - &validation_data, - id, - ); + let relay_chain_node = relay_chain_node.clone(); async move { + let parachain_inherent = + cumulus_primitives_parachain_inherent::ParachainInherentData::create_at( + relay_parent, + &relay_chain_node, + &validation_data, + id, + ) + .await; + let time = sp_timestamp::InherentDataProvider::from_system_time(); let parachain_inherent = parachain_inherent.ok_or_else(|| { @@ -321,12 +331,10 @@ fn build_consensus( } }; - Ok(build_nimbus_consensus(BuildNimbusConsensusParams { + Ok(NimbusConsensus::build(BuildNimbusConsensusParams { para_id: id, proposer_factory, block_import: client.clone(), - relay_chain_client: relay_chain_node.client.clone(), - relay_chain_backend: relay_chain_node.backend.clone(), parachain_client: client.clone(), keystore, skip_prediction: force_authoring, @@ -426,9 +434,13 @@ pub fn new_dev( let client_set_aside_for_cidp = client.clone(); + // Create channels for mocked XCM messages. + let (_downward_xcm_sender, downward_xcm_receiver) = flume::bounded::>(100); + let (_hrmp_xcm_sender, hrmp_xcm_receiver) = flume::bounded::<(ParaId, Vec)>(100); + task_manager.spawn_essential_handle().spawn_blocking( "authorship_task", - None, + Some("block-authoring"), run_manual_seal(ManualSealParams { block_import: client.clone(), env, @@ -436,7 +448,10 @@ pub fn new_dev( pool: transaction_pool.clone(), commands_stream, select_chain, - consensus_data_provider: None, + consensus_data_provider: Some(Box::new(NimbusManualSealConsensusDataProvider { + keystore: keystore_container.sync_keystore(), + client: client.clone(), + })), create_inherent_data_providers: move |block: H256, ()| { let current_para_block = client_set_aside_for_cidp .number(block) @@ -444,6 +459,10 @@ pub fn new_dev( .expect("Header passed in as parent should be present in backend."); let author_id = author_id.clone(); + let client_for_xcm = client_set_aside_for_cidp.clone(); + let downward_xcm_receiver = downward_xcm_receiver.clone(); + let hrmp_xcm_receiver = hrmp_xcm_receiver.clone(); + async move { let time = sp_timestamp::InherentDataProvider::from_system_time(); @@ -451,6 +470,14 @@ pub fn new_dev( current_para_block, relay_offset: 1000, relay_blocks_per_para_block: 2, + xcm_config: MockXcmConfig::new( + &*client_for_xcm, + block, + Default::default(), + Default::default(), + ), + raw_downward_messages: downward_xcm_receiver.drain().collect(), + raw_horizontal_messages: hrmp_xcm_receiver.drain().collect(), }; let author = diff --git a/pallets/author-mapping/Cargo.toml b/pallets/author-mapping/Cargo.toml index ce22fe70..39271ffb 100644 --- a/pallets/author-mapping/Cargo.toml +++ b/pallets/author-mapping/Cargo.toml @@ -1,26 +1,26 @@ [package] name = "pallet-author-mapping" -version = "2.0.4" +version = "2.0.5" authors = ["PureStake"] edition = "2021" description = "Maps AuthorIds to AccountIds Useful for associating consensus authors with in-runtime accounts" [dependencies] log = { version = "0.4", default-features = false } -nimbus-primitives = { git = "https://github.com/pontem-network/nimbus.git", branch = "polkadot-v0.9.13", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -parity-scale-codec = { version = "2.0.0", default-features = false, features=["derive"] } +nimbus-primitives = { git = "https://github.com/pontem-network/nimbus", branch = "polkadot-v0.9.16", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +parity-scale-codec = { version = "2.3.1", default-features = false, features=["derive"] } serde = { version = "1.0.101", optional=true } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false, optional = true } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false, optional = true } scale-info = { version = "1.0", default-features = false, features = ["derive"] } [dev-dependencies] -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } [features] default = ["std"] diff --git a/pallets/author-mapping/src/lib.rs b/pallets/author-mapping/src/lib.rs index 3c8ffd20..35da6d2a 100644 --- a/pallets/author-mapping/src/lib.rs +++ b/pallets/author-mapping/src/lib.rs @@ -17,7 +17,7 @@ //! Maps Author Ids as used in nimbus consensus layer to account ids as used i nthe runtime. //! This should likely be moved to nimbus eventually. //! -//! This pallet maps AuthorId => AccountId which is most useful when using propositional style +//! This pallet maps NimbusId => AccountId which is most useful when using propositional style //! queries. This mapping will likely need to go the other way if using exhaustive authority sets. //! That could either be a seperate pallet, or this pallet could implement a two-way mapping. But //! for now it it one-way @@ -45,7 +45,7 @@ pub mod pallet { use frame_support::pallet_prelude::*; use frame_support::traits::{Currency, ReservableCurrency}; use frame_system::pallet_prelude::*; - use nimbus_primitives::AccountLookup; + use nimbus_primitives::{AccountLookup, NimbusId}; pub type BalanceOf = <::DepositCurrency as Currency< ::AccountId, @@ -58,6 +58,7 @@ pub mod pallet { } #[pallet::pallet] + #[pallet::without_storage_info] pub struct Pallet(PhantomData); /// Configuration trait of this pallet. We tightly couple to Parachain Staking in order to @@ -67,11 +68,9 @@ pub mod pallet { pub trait Config: frame_system::Config { /// Overarching event type type Event: From> + IsType<::Event>; - /// The type of authority id that will be used at the consensus layer. - type AuthorId: Member + Parameter + MaybeSerializeDeserialize + Default; /// Currency in which the security deposit will be taken. type DepositCurrency: Currency + ReservableCurrency; - /// The amount that should be taken as a security deposit when registering an AuthorId. + /// The amount that should be taken as a security deposit when registering an NimbusId. type DepositAmount: Get<>::Balance>; /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; @@ -86,32 +85,32 @@ pub mod pallet { NotYourAssociation, /// This account cannot set an author because it cannon afford the security deposit CannotAffordSecurityDeposit, - /// The AuthorId in question is already associated and cannot be overwritten + /// The NimbusId in question is already associated and cannot be overwritten AlreadyAssociated, } #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { - /// An AuthorId has been registered and mapped to an AccountId. - AuthorRegistered(T::AuthorId, T::AccountId), - /// An AuthorId has been de-registered, and its AccountId mapping removed. - AuthorDeRegistered(T::AuthorId), - /// An AuthorId has been registered, replacing a previous registration and its mapping. - AuthorRotated(T::AuthorId, T::AccountId), - /// An AuthorId has been forcibly deregistered after not being rotated or cleaned up. + /// An NimbusId has been registered and mapped to an AccountId. + AuthorRegistered(NimbusId, T::AccountId), + /// An NimbusId has been de-registered, and its AccountId mapping removed. + AuthorDeRegistered(NimbusId), + /// An NimbusId has been registered, replacing a previous registration and its mapping. + AuthorRotated(NimbusId, T::AccountId), + /// An NimbusId has been forcibly deregistered after not being rotated or cleaned up. /// The reporteing account has been rewarded accordingly. - DefunctAuthorBusted(T::AuthorId, T::AccountId), + DefunctAuthorBusted(NimbusId, T::AccountId), } #[pallet::call] impl Pallet { - /// Register your AuthorId onchain so blocks you author are associated with your account. + /// Register your NimbusId onchain so blocks you author are associated with your account. /// /// Users who have been (or will soon be) elected active collators in staking, /// should submit this extrinsic to have their blocks accepted and earn rewards. #[pallet::weight(::WeightInfo::add_association())] - pub fn add_association(origin: OriginFor, author_id: T::AuthorId) -> DispatchResult { + pub fn add_association(origin: OriginFor, author_id: NimbusId) -> DispatchResult { let account_id = ensure_signed(origin)?; ensure!( @@ -126,15 +125,15 @@ pub mod pallet { Ok(()) } - /// Change your AuthorId. + /// Change your Mapping. /// /// This is useful for normal key rotation or for when switching from one physical collator /// machine to another. No new security deposit is required. #[pallet::weight(::WeightInfo::update_association())] pub fn update_association( origin: OriginFor, - old_author_id: T::AuthorId, - new_author_id: T::AuthorId, + old_author_id: NimbusId, + new_author_id: NimbusId, ) -> DispatchResult { let account_id = ensure_signed(origin)?; @@ -145,23 +144,27 @@ pub mod pallet { account_id == stored_info.account, Error::::NotYourAssociation ); + ensure!( + MappingWithDeposit::::get(&new_author_id).is_none(), + Error::::AlreadyAssociated + ); - MappingWithDeposit::::insert(&new_author_id, &stored_info); MappingWithDeposit::::remove(&old_author_id); + MappingWithDeposit::::insert(&new_author_id, &stored_info); >::deposit_event(Event::AuthorRotated(new_author_id, stored_info.account)); Ok(()) } - /// Clear your AuthorId. + /// Clear your Mapping. /// /// This is useful when you are no longer an author and would like to re-claim your security /// deposit. #[pallet::weight(::WeightInfo::clear_association())] pub fn clear_association( origin: OriginFor, - author_id: T::AuthorId, + author_id: NimbusId, ) -> DispatchResultWithPostInfo { let account_id = ensure_signed(origin)?; @@ -181,42 +184,11 @@ pub mod pallet { Ok(().into()) } - - //TODO maybe in the future we will add some more incentivization for key cleanup and also - // proper key rotation - // /// The portion of the security deposit that goes to the the account who reports it - // /// occupying space after it should have been cleaned or rotated. - // pub const NARC_REWARD: Percent = Percent::from_percent(5); - - // /// The period of time after which an AuthorId can be reported as defunct. - // /// This value should be roughly the recommended key rotation period. - // pub const NARC_GRACE_PERIOD: u32 = 2_000; - // - // /// Narc on another account for having a useless association and collect a bounty. - // /// - // /// This incentivizes good citizenship in the form of cleaning up others' defunct - // /// associations. When you clean up another account's association, you will receive X - // /// percent of their security deposit. - // /// - // /// No association can be cleaned up within the initial grace period which allows collators - // /// some time to get their associations onchain before they become active, and to clean up - // /// after they are no longer active. - // /// - // /// This also _forces_ collators to rotate their keys regularly because failing to will - // /// make their mappings ripe for narcing. If an active collator gets its association reaped - // /// they will lose out on their block rewards (and in the future potentially be slashed). - // #[pallet::weight(0)] - // pub fn narc_defunct_association( - // origin: OriginFor, - // author_id: T::AuthorId, - // ) -> DispatchResult { - // todo!() - // } } impl Pallet { pub fn enact_registration( - author_id: &T::AuthorId, + author_id: &NimbusId, account_id: &T::AccountId, ) -> DispatchResult { let deposit = T::DepositAmount::get(); @@ -237,12 +209,12 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn account_and_deposit_of)] - /// We maintain a mapping from the AuthorIds used in the consensus layer + /// We maintain a mapping from the NimbusIds used in the consensus layer /// to the AccountIds runtime (including this staking pallet). pub type MappingWithDeposit = StorageMap< _, Blake2_128Concat, - T::AuthorId, + NimbusId, RegistrationInfo>, OptionQuery, >; @@ -251,7 +223,7 @@ pub mod pallet { /// Genesis config for author mapping pallet pub struct GenesisConfig { /// The associations that should exist at chain genesis - pub mappings: Vec<(T::AuthorId, T::AccountId)>, + pub mappings: Vec<(NimbusId, T::AccountId)>, } #[cfg(feature = "std")] @@ -272,8 +244,8 @@ pub mod pallet { } } - impl AccountLookup for Pallet { - fn lookup_account(author: &T::AuthorId) -> Option { + impl AccountLookup for Pallet { + fn lookup_account(author: &NimbusId) -> Option { Self::account_id_of(author) } } @@ -281,7 +253,7 @@ pub mod pallet { impl Pallet { /// A helper function to lookup the account id associated with the given author id. This is /// the primary lookup that this pallet is responsible for. - pub fn account_id_of(author_id: &T::AuthorId) -> Option { + pub fn account_id_of(author_id: &NimbusId) -> Option { Self::account_and_deposit_of(author_id).map(|info| info.account) } } diff --git a/pallets/author-mapping/src/migrations.rs b/pallets/author-mapping/src/migrations.rs index b0f64727..798778c9 100644 --- a/pallets/author-mapping/src/migrations.rs +++ b/pallets/author-mapping/src/migrations.rs @@ -26,6 +26,7 @@ use frame_support::{ use sp_std::convert::TryInto; //TODO sometimes this is unused, sometimes its necessary use sp_std::vec::Vec; +use nimbus_primitives::NimbusId; /// Migrates the AuthorMapping's storage map fro mthe insecure Twox64 hasher to the secure /// BlakeTwo hasher. @@ -39,7 +40,7 @@ impl OnRuntimeUpgrade for TwoXToBlake { // Read all the data into memory. // https://crates.parity.io/frame_support/storage/migration/fn.storage_key_iter.html let stored_data: Vec<_> = storage_key_iter::< - T::AuthorId, + NimbusId, RegistrationInfo>, Twox64Concat, >(pallet_prefix, storage_item_prefix) @@ -56,7 +57,7 @@ impl OnRuntimeUpgrade for TwoXToBlake { // Assert that old storage is empty assert!(storage_key_iter::< - T::AuthorId, + NimbusId, RegistrationInfo>, Twox64Concat, >(pallet_prefix, storage_item_prefix) @@ -106,7 +107,7 @@ impl OnRuntimeUpgrade for TwoXToBlake { // Read an example pair from old storage and set it aside in temp storage if mapping_count > 0 { let example_pair = storage_key_iter::< - T::AuthorId, + NimbusId, RegistrationInfo>, Twox64Concat, >(pallet_prefix, storage_item_prefix) @@ -132,7 +133,7 @@ impl OnRuntimeUpgrade for TwoXToBlake { // Check that our example pair is still well-mapped after the migration if new_mapping_count > 0 { let (account, original_info): ( - T::AuthorId, + NimbusId, RegistrationInfo>, ) = Self::get_temp_storage("example_pair").expect("qed"); let migrated_info = MappingWithDeposit::::get(account).expect("qed"); diff --git a/pallets/author-mapping/src/mock.rs b/pallets/author-mapping/src/mock.rs index 79d61d1e..b953d026 100644 --- a/pallets/author-mapping/src/mock.rs +++ b/pallets/author-mapping/src/mock.rs @@ -18,20 +18,21 @@ use crate as pallet_author_mapping; use frame_support::{ construct_runtime, parameter_types, - traits::{Everything, GenesisBuild}, + traits::{Everything, GenesisBuild, ConstU32}, weights::Weight, }; use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; -use sp_core::H256; +use sp_core::{H256, ByteArray}; use sp_io; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, Perbill, RuntimeDebug, }; +use nimbus_primitives::NimbusId; #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, RuntimeDebug, TypeInfo)] @@ -39,14 +40,21 @@ pub enum TestAuthor { Alice, Bob, Charlie, - Dave, - Eve, } impl Default for TestAuthor { fn default() -> TestAuthor { TestAuthor::Alice } } +impl Into for TestAuthor { + fn into(self) -> NimbusId { + match self { + Self::Alice => NimbusId::from_slice(&[0u8; 32]).unwrap(), + Self::Bob => NimbusId::from_slice(&[1u8; 32]).unwrap(), + Self::Charlie => NimbusId::from_slice(&[2u8; 32]).unwrap(), + } + } +} pub type AccountId = u64; pub type Balance = u128; pub type BlockNumber = u64; @@ -97,6 +105,7 @@ impl frame_system::Config for Runtime { type BlockLength = (); type SS58Prefix = (); type OnSetCode = (); + type MaxConsumers = ConstU32<12>; } parameter_types! { pub const ExistentialDeposit: u128 = 1; @@ -118,7 +127,6 @@ parameter_types! { } impl pallet_author_mapping::Config for Runtime { type Event = Event; - type AuthorId = TestAuthor; type DepositCurrency = Balances; type DepositAmount = DepositAmount; type WeightInfo = (); @@ -130,7 +138,7 @@ pub(crate) struct ExtBuilder { /// Accounts endowed with balances balances: Vec<(AccountId, Balance)>, /// AuthorId -> AccoutId mappings - mappings: Vec<(TestAuthor, AccountId)>, + mappings: Vec<(NimbusId, AccountId)>, } impl Default for ExtBuilder { @@ -148,7 +156,7 @@ impl ExtBuilder { self } - pub(crate) fn with_mappings(mut self, mappings: Vec<(TestAuthor, AccountId)>) -> Self { + pub(crate) fn with_mappings(mut self, mappings: Vec<(NimbusId, AccountId)>) -> Self { self.mappings = mappings; self } diff --git a/pallets/author-mapping/src/tests.rs b/pallets/author-mapping/src/tests.rs index b521fbe4..0a022edc 100644 --- a/pallets/author-mapping/src/tests.rs +++ b/pallets/author-mapping/src/tests.rs @@ -26,14 +26,17 @@ use frame_support::{assert_noop, assert_ok}; fn genesis_builder_works() { ExtBuilder::default() .with_balances(vec![(1, 1000)]) - .with_mappings(vec![(TestAuthor::Alice, 1)]) + .with_mappings(vec![(TestAuthor::Alice.into(), 1)]) .build() .execute_with(|| { assert!(System::events().is_empty()); assert_eq!(Balances::free_balance(&1), 900); assert_eq!(Balances::reserved_balance(&1), 100); - assert_eq!(AuthorMapping::account_id_of(&TestAuthor::Alice), Some(1)); - assert_eq!(AuthorMapping::account_id_of(&TestAuthor::Bob), None); + assert_eq!( + AuthorMapping::account_id_of(&TestAuthor::Alice.into()), + Some(1) + ); + assert_eq!(AuthorMapping::account_id_of(&TestAuthor::Bob.into()), None); }) } @@ -45,16 +48,19 @@ fn eligible_account_can_register() { .execute_with(|| { assert_ok!(AuthorMapping::add_association( Origin::signed(2), - TestAuthor::Bob + TestAuthor::Bob.into() )); assert_eq!(Balances::free_balance(&2), 900); assert_eq!(Balances::reserved_balance(&2), 100); - assert_eq!(AuthorMapping::account_id_of(&TestAuthor::Bob), Some(2)); + assert_eq!( + AuthorMapping::account_id_of(&TestAuthor::Bob.into()), + Some(2) + ); assert_eq!( last_event(), - MetaEvent::AuthorMapping(Event::AuthorRegistered(TestAuthor::Bob, 2)) + MetaEvent::AuthorMapping(Event::AuthorRegistered(TestAuthor::Bob.into(), 2)) ); }) } @@ -66,12 +72,15 @@ fn cannot_register_without_deposit() { .build() .execute_with(|| { assert_noop!( - AuthorMapping::add_association(Origin::signed(2), TestAuthor::Alice), + AuthorMapping::add_association(Origin::signed(2), TestAuthor::Alice.into()), Error::::CannotAffordSecurityDeposit ); assert_eq!(Balances::free_balance(&2), 10); - assert_eq!(AuthorMapping::account_id_of(&TestAuthor::Alice), None); + assert_eq!( + AuthorMapping::account_id_of(&TestAuthor::Alice.into()), + None + ); }) } @@ -84,35 +93,44 @@ fn double_registration_costs_twice_as_much() { // Register once as Bob assert_ok!(AuthorMapping::add_association( Origin::signed(2), - TestAuthor::Bob + TestAuthor::Bob.into() )); assert_eq!(Balances::free_balance(&2), 900); assert_eq!(Balances::reserved_balance(&2), 100); - assert_eq!(AuthorMapping::account_id_of(&TestAuthor::Bob), Some(2)); + assert_eq!( + AuthorMapping::account_id_of(&TestAuthor::Bob.into()), + Some(2) + ); assert_eq!( last_event(), - MetaEvent::AuthorMapping(Event::AuthorRegistered(TestAuthor::Bob, 2)) + MetaEvent::AuthorMapping(Event::AuthorRegistered(TestAuthor::Bob.into(), 2)) ); // Register again as Alice assert_ok!(AuthorMapping::add_association( Origin::signed(2), - TestAuthor::Alice + TestAuthor::Alice.into() )); assert_eq!(Balances::free_balance(&2), 800); assert_eq!(Balances::reserved_balance(&2), 200); - assert_eq!(AuthorMapping::account_id_of(&TestAuthor::Alice), Some(2)); + assert_eq!( + AuthorMapping::account_id_of(&TestAuthor::Alice.into()), + Some(2) + ); assert_eq!( last_event(), - MetaEvent::AuthorMapping(Event::AuthorRegistered(TestAuthor::Alice, 2)) + MetaEvent::AuthorMapping(Event::AuthorRegistered(TestAuthor::Alice.into(), 2)) ); // Should still be registered as Bob as well - assert_eq!(AuthorMapping::account_id_of(&TestAuthor::Bob), Some(2)); + assert_eq!( + AuthorMapping::account_id_of(&TestAuthor::Bob.into()), + Some(2) + ); }) } @@ -120,21 +138,24 @@ fn double_registration_costs_twice_as_much() { fn registered_account_can_clear() { ExtBuilder::default() .with_balances(vec![(1, 1000)]) - .with_mappings(vec![(TestAuthor::Alice, 1)]) + .with_mappings(vec![(TestAuthor::Alice.into(), 1)]) .build() .execute_with(|| { assert_ok!(AuthorMapping::clear_association( Origin::signed(1), - TestAuthor::Alice + TestAuthor::Alice.into() )); assert_eq!(Balances::free_balance(&1), 1000); assert_eq!(Balances::reserved_balance(&1), 0); - assert_eq!(AuthorMapping::account_id_of(&TestAuthor::Alice), None); + assert_eq!( + AuthorMapping::account_id_of(&TestAuthor::Alice.into()), + None + ); assert_eq!( last_event(), - MetaEvent::AuthorMapping(Event::AuthorDeRegistered(TestAuthor::Alice)) + MetaEvent::AuthorMapping(Event::AuthorDeRegistered(TestAuthor::Alice.into())) ); }) } @@ -143,7 +164,7 @@ fn registered_account_can_clear() { fn unregistered_author_cannot_be_cleared() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - AuthorMapping::clear_association(Origin::signed(1), TestAuthor::Alice), + AuthorMapping::clear_association(Origin::signed(1), TestAuthor::Alice.into()), Error::::AssociationNotFound ); }) @@ -153,11 +174,11 @@ fn unregistered_author_cannot_be_cleared() { fn registered_author_cannot_be_cleared_by_non_owner() { ExtBuilder::default() .with_balances(vec![(1, 1000)]) - .with_mappings(vec![(TestAuthor::Alice, 1)]) + .with_mappings(vec![(TestAuthor::Alice.into(), 1)]) .build() .execute_with(|| { assert_noop!( - AuthorMapping::clear_association(Origin::signed(2), TestAuthor::Alice), + AuthorMapping::clear_association(Origin::signed(2), TestAuthor::Alice.into()), Error::::NotYourAssociation ); }) @@ -167,11 +188,11 @@ fn registered_author_cannot_be_cleared_by_non_owner() { fn registered_author_cannot_be_overwritten() { ExtBuilder::default() .with_balances(vec![(1, 1000)]) - .with_mappings(vec![(TestAuthor::Alice, 1)]) + .with_mappings(vec![(TestAuthor::Alice.into(), 1)]) .build() .execute_with(|| { assert_noop!( - AuthorMapping::add_association(Origin::signed(2), TestAuthor::Alice), + AuthorMapping::add_association(Origin::signed(2), TestAuthor::Alice.into()), Error::::AlreadyAssociated ); }) @@ -181,17 +202,20 @@ fn registered_author_cannot_be_overwritten() { fn registered_can_rotate() { ExtBuilder::default() .with_balances(vec![(2, 1000)]) - .with_mappings(vec![(TestAuthor::Bob, 2)]) + .with_mappings(vec![(TestAuthor::Bob.into(), 2)]) .build() .execute_with(|| { assert_ok!(AuthorMapping::update_association( Origin::signed(2), - TestAuthor::Bob, - TestAuthor::Charlie + TestAuthor::Bob.into(), + TestAuthor::Charlie.into() )); - assert_eq!(AuthorMapping::account_id_of(&TestAuthor::Bob), None); - assert_eq!(AuthorMapping::account_id_of(&TestAuthor::Charlie), Some(2)); + assert_eq!(AuthorMapping::account_id_of(&TestAuthor::Bob.into()), None); + assert_eq!( + AuthorMapping::account_id_of(&TestAuthor::Charlie.into()), + Some(2) + ); // Should still only ahve paid a single security deposit assert_eq!(Balances::free_balance(&2), 900); @@ -205,8 +229,8 @@ fn unregistered_author_cannot_be_rotated() { assert_noop!( AuthorMapping::update_association( Origin::signed(2), - TestAuthor::Alice, - TestAuthor::Bob + TestAuthor::Alice.into(), + TestAuthor::Bob.into() ), Error::::AssociationNotFound ); @@ -217,20 +241,38 @@ fn unregistered_author_cannot_be_rotated() { fn registered_author_cannot_be_rotated_by_non_owner() { ExtBuilder::default() .with_balances(vec![(1, 1000)]) - .with_mappings(vec![(TestAuthor::Alice, 1)]) + .with_mappings(vec![(TestAuthor::Alice.into(), 1)]) .build() .execute_with(|| { assert_noop!( AuthorMapping::update_association( Origin::signed(2), - TestAuthor::Alice, - TestAuthor::Bob + TestAuthor::Alice.into(), + TestAuthor::Bob.into() ), Error::::NotYourAssociation ); }) } +#[test] +fn rotating_to_the_same_author_id_leaves_registration_in_tact() { + ExtBuilder::default() + .with_balances(vec![(1, 1000)]) + .with_mappings(vec![(TestAuthor::Alice.into(), 1)]) + .build() + .execute_with(|| { + assert_noop!( + AuthorMapping::update_association( + Origin::signed(1), + TestAuthor::Alice.into(), + TestAuthor::Alice.into() + ), + Error::::AlreadyAssociated + ); + }) +} + //TODO Test ideas in case we bring back the narc extrinsic // unstaked account can be narced after period // unstaked account cannot be narced before period diff --git a/pallets/currencies/Cargo.toml b/pallets/currencies/Cargo.toml index a18a0e3c..af5d242c 100644 --- a/pallets/currencies/Cargo.toml +++ b/pallets/currencies/Cargo.toml @@ -8,26 +8,26 @@ edition = "2021" serde = { version = "1.0", optional = true } codec = { package = "parity-scale-codec", version = "2.3.1", default-features = false } scale-info = { version = "1.0", default-features = false, features = ["derive"] } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } # Orml dependencies -orml-traits = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } -orml-utilities = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } +orml-traits = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } +orml-utilities = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } # Local dependencies primitives = { default-features = false, path = "../../primitives" } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } -pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } -orml-tokens = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } +pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } +orml-tokens = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } [features] default = ["std"] diff --git a/pallets/currencies/src/lib.rs b/pallets/currencies/src/lib.rs index 2bd505c7..e762ead6 100644 --- a/pallets/currencies/src/lib.rs +++ b/pallets/currencies/src/lib.rs @@ -22,7 +22,7 @@ #![allow(clippy::unused_unit)] #![allow(clippy::upper_case_acronyms)] -use codec::{Codec, FullCodec}; +use codec::{Codec, FullCodec, MaxEncodedLen}; use frame_support::{ pallet_prelude::*, traits::{ @@ -83,7 +83,8 @@ pub mod module { + Copy + MaybeSerializeDeserialize + Debug - + scale_info::TypeInfo; + + scale_info::TypeInfo + + MaxEncodedLen; type MultiCurrency: TransferAll + MultiCurrencyExtended + MultiLockableCurrency @@ -859,7 +860,8 @@ where + Copy + MaybeSerializeDeserialize + Debug - + Default, + + Default + + MaxEncodedLen, Currency: PalletCurrency, T: Config, { diff --git a/pallets/currencies/src/mock.rs b/pallets/currencies/src/mock.rs index 16a9efe1..6dfa8218 100644 --- a/pallets/currencies/src/mock.rs +++ b/pallets/currencies/src/mock.rs @@ -22,12 +22,12 @@ use frame_support::{ ord_parameter_types, parameter_types, - traits::{Everything, GenesisBuild, Nothing}, + traits::{Everything, GenesisBuild, Nothing, ConstU32}, PalletId, }; use orml_traits::parameter_type_with_key; use sp_core::{H256, crypto::Ss58Codec}; -use codec::{Decode, Encode}; +use codec::{Decode, Encode, MaxEncodedLen}; use sp_runtime::{ testing::Header, @@ -43,7 +43,19 @@ use serde::{Deserialize, Serialize}; use scale_info::TypeInfo; // Currencies id. -#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, PartialOrd, Ord, TypeInfo)] +#[derive( + Encode, + Decode, + Eq, + PartialEq, + Copy, + Clone, + RuntimeDebug, + PartialOrd, + Ord, + TypeInfo, + MaxEncodedLen, +)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum CurrencyId { // Relaychain's currency. @@ -88,6 +100,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); + type MaxConsumers = ConstU32<12>; } type Balance = u128; @@ -178,8 +191,8 @@ pub type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, diff --git a/pallets/groupsign/Cargo.toml b/pallets/groupsign/Cargo.toml index ab5e3dec..4eb02ab8 100644 --- a/pallets/groupsign/Cargo.toml +++ b/pallets/groupsign/Cargo.toml @@ -14,17 +14,17 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { default-features = false , package = "parity-scale-codec", version = "2.3.1" } scale-info = { default-features = false, version = "1.0", features = ["derive"] } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } -sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +sp-io = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } getrandom = { version = "0.2.3", optional = true } [dev-dependencies] -sp-keystore = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +sp-keystore = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } [features] default = ['std'] diff --git a/pallets/groupsign/src/mock.rs b/pallets/groupsign/src/mock.rs index 987d5f1e..41e27792 100644 --- a/pallets/groupsign/src/mock.rs +++ b/pallets/groupsign/src/mock.rs @@ -1,6 +1,6 @@ use crate::{self as groupsign, weights::PontemWeights}; use codec::{Decode, Encode}; -use frame_support::parameter_types; +use frame_support::{parameter_types, traits::ConstU32}; use frame_system as system; use scale_info::TypeInfo; use sp_core::{H256, sr25519}; @@ -54,6 +54,7 @@ impl system::Config for Test { type SystemWeightInfo = (); type SS58Prefix = SS58Prefix; type OnSetCode = (); + type MaxConsumers = ConstU32<12>; } impl groupsign::Config for Test { @@ -67,7 +68,7 @@ impl groupsign::Config for Test { type Signature = AnySignature; } -#[derive(Eq, PartialEq, Clone, Default, Encode, Decode, TypeInfo, Debug)] +#[derive(Eq, PartialEq, Clone, Encode, Decode, TypeInfo, Debug)] pub struct AnySignature(sr25519::Signature); impl Verify for AnySignature { diff --git a/pallets/parachain-staking/Cargo.toml b/pallets/parachain-staking/Cargo.toml index f299eaed..f28fcb8d 100644 --- a/pallets/parachain-staking/Cargo.toml +++ b/pallets/parachain-staking/Cargo.toml @@ -6,23 +6,23 @@ edition = "2021" description = "parachain staking pallet for collator selection and reward distribution" [dependencies] -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false, optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false, optional = true } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } log = "0.4" -nimbus-primitives = { git = "https://github.com/pontem-network/nimbus.git", branch = "polkadot-v0.9.13", default-features = false } -parity-scale-codec = { version = "2.2", default-features = false, features = ["derive"] } +nimbus-primitives = { git = "https://github.com/pontem-network/nimbus", branch = "polkadot-v0.9.16", default-features = false } +parity-scale-codec = { version = "2.3.1", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } substrate-fixed = { default-features = false, git = "https://github.com/encointer/substrate-fixed" } scale-info = { version = "1.0", default-features = false, features = ["derive"] } [dev-dependencies] -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13"} +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16"} similar-asserts = "1.1.0" -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } [features] default = ["std"] diff --git a/pallets/parachain-staking/migrations.md b/pallets/parachain-staking/migrations.md index 62b05a35..184693fa 100644 --- a/pallets/parachain-staking/migrations.md +++ b/pallets/parachain-staking/migrations.md @@ -1,5 +1,19 @@ # Migration History +## Increase max delegations per candidate + +- [Migration PR `#1096`](https://github.com/PureStake/moonbeam/pull/1096) +- [Migratio bugfix `#1112`](https://github.com/PureStake/moonbeam/pull/1112) + +## Manual Exits and Patch Lack of Delay for bond\_{more, less} + +- [Migration PR `#810`](https://github.com/PureStake/moonbeam/pull/810) +- [Migration Removal PR `#?`]() + +## Purge Stale Storage + +- [Migration PR `#970`](https://github.com/PureStake/moonbeam/pull/970) + ## Delay nominator exits by changing NominatorState and ExitQueue - [Migration PR `#610`](https://github.com/PureStake/moonbeam/pull/610) diff --git a/pallets/parachain-staking/src/benchmarks.rs b/pallets/parachain-staking/src/benchmarks.rs index 7575fc4b..7ef77e30 100644 --- a/pallets/parachain-staking/src/benchmarks.rs +++ b/pallets/parachain-staking/src/benchmarks.rs @@ -1,4 +1,4 @@ -// Copyright 2019-2021 PureStake Inc. +// Copyright 2019-2022 PureStake Inc. // This file is part of Moonbeam. // Moonbeam is free software: you can redistribute it and/or modify @@ -17,7 +17,10 @@ #![cfg(feature = "runtime-benchmarks")] //! Benchmarking -use crate::{BalanceOf, Call, Config, Pallet, Range}; +use crate::{ + BalanceOf, Call, CandidateBondLessRequest, Config, DelegationChange, DelegationRequest, + Pallet, Range, +}; use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite}; use frame_support::traits::{Currency, Get, OnFinalize, OnInitialize, ReservableCurrency}; use frame_system::RawOrigin; @@ -25,67 +28,146 @@ use nimbus_primitives::EventHandler; use sp_runtime::{Perbill, Percent}; use sp_std::{collections::btree_map::BTreeMap, vec::Vec}; -/// Default balance amount is minimum collator stake -fn default_balance() -> BalanceOf { +/// Minimum collator candidate stake +fn min_candidate_stk() -> BalanceOf { <::MinCollatorStk as Get>>::get() } +/// Minimum delegator stake +fn min_delegator_stk() -> BalanceOf { + <::MinDelegatorStk as Get>>::get() +} + /// Create a funded user. +/// Extra + min_candidate_stk is total minted funds +/// Returns tuple (id, balance) fn create_funded_user( string: &'static str, n: u32, extra: BalanceOf, -) -> T::AccountId { +) -> (T::AccountId, BalanceOf) { const SEED: u32 = 0; let user = account(string, n, SEED); - let default_balance = default_balance::(); - let total = default_balance + extra; + let min_candidate_stk = min_candidate_stk::(); + let total = min_candidate_stk + extra; T::Currency::make_free_balance_be(&user, total); T::Currency::issue(total); - user + (user, total) } -/// Create a funded nominator. Base balance is MinCollatorStk == default_balance -/// but the amount for the nomination is MinNominatorStk << MinCollatorStk => the rest + extra -/// is free balance for the returned account. -fn create_funded_nominator( +/// Create a funded delegator. +fn create_funded_delegator( string: &'static str, n: u32, extra: BalanceOf, collator: T::AccountId, - collator_nominator_count: u32, + min_bond: bool, + collator_delegator_count: u32, ) -> Result { - let user = create_funded_user::(string, n, extra); - Pallet::::nominate( + let (user, total) = create_funded_user::(string, n, extra); + let bond = if min_bond { + min_delegator_stk::() + } else { + total + }; + Pallet::::delegate( RawOrigin::Signed(user.clone()).into(), collator, - <::MinNominatorStk as Get>>::get(), - collator_nominator_count, - 0u32, // first nomination for all calls + bond, + collator_delegator_count, + 0u32, // first delegation for all calls )?; Ok(user) } -/// Create a funded collator. Base amount is MinCollatorStk == default_balance but the -/// last parameter `extra` represents how much additional balance is minted to the collator. +/// Create a funded collator. fn create_funded_collator( string: &'static str, n: u32, extra: BalanceOf, + min_bond: bool, candidate_count: u32, ) -> Result { - let user = create_funded_user::(string, n, extra); + let (user, total) = create_funded_user::(string, n, extra); + let bond = if min_bond { + min_candidate_stk::() + } else { + total + }; Pallet::::join_candidates( RawOrigin::Signed(user.clone()).into(), - default_balance::(), + bond, candidate_count, )?; Ok(user) } +/// Run to end block and author +fn roll_to_and_author(round_delay: u32, author: T::AccountId) { + let total_rounds = round_delay + 1u32; + let round_length: T::BlockNumber = Pallet::::round().length.into(); + let mut now = >::block_number() + 1u32.into(); + let end = Pallet::::round().first + (round_length * total_rounds.into()); + while now < end { + Pallet::::note_author(author.clone()); + >::on_finalize(>::block_number()); + >::set_block_number( + >::block_number() + 1u32.into(), + ); + >::on_initialize(>::block_number()); + Pallet::::on_initialize(>::block_number()); + now += 1u32.into(); + } +} + const USER_SEED: u32 = 999666; benchmarks! { + // HOTFIX BENCHMARK + hotfix_remove_delegation_requests { + let x in 2..<::MaxTopDelegationsPerCandidate as Get>::get() + + <::MaxBottomDelegationsPerCandidate as Get>::get(); + let mut delegators: Vec = Vec::new(); + let collator = create_funded_collator::( + "candidate", + 100, + 0u32.into(), + true, + 1u32 + )?; + let mut col_del_count = 0u32; + for i in 1..x { + let seed = USER_SEED + i; + let delegator = create_funded_delegator::( + "delegator", + seed, + 0u32.into(), + collator.clone(), + true, + col_del_count, + )?; + delegators.push(delegator); + col_del_count += 1u32; + } + }: _(RawOrigin::Root, delegators) + verify { } + + hotfix_update_candidate_pool_value { + let x in 5..200; + let mut candidates: Vec = Vec::new(); + for i in 1..x { + let account = create_funded_collator::( + "candidate", + i + 100, + 0u32.into(), + true, + i + )?; + candidates.push(account); + } + }: _(RawOrigin::Root, candidates) + verify { } + // MONETARY ORIGIN DISPATCHABLES set_staking_expectations { @@ -126,7 +208,9 @@ benchmarks! { // ROOT DISPATCHABLES - set_total_selected {}: _(RawOrigin::Root, 100u32) + set_total_selected { + Pallet::::set_blocks_per_round(RawOrigin::Root.into(), 100u32)?; + }: _(RawOrigin::Root, 100u32) verify { assert_eq!(Pallet::::total_selected(), 100u32); } @@ -153,19 +237,107 @@ benchmarks! { "collator", seed, 0u32.into(), + true, candidate_count )?; candidate_count += 1u32; } - let caller: T::AccountId = create_funded_user::("caller", USER_SEED, 0u32.into()); - }: _(RawOrigin::Signed(caller.clone()), default_balance::(), candidate_count) + let (caller, min_candidate_stk) = create_funded_user::("caller", USER_SEED, 0u32.into()); + }: _(RawOrigin::Signed(caller.clone()), min_candidate_stk, candidate_count) verify { assert!(Pallet::::is_candidate(&caller)); } // This call schedules the collator's exit and removes them from the candidate pool - // -> it retains the self-bond and nominator bonds - leave_candidates { + // -> it retains the self-bond and delegator bonds + schedule_leave_candidates { + let x in 3..1_000; + // Worst Case Complexity is removal from an ordered list so \exists full list before call + let mut candidate_count = 1u32; + for i in 2..x { + let seed = USER_SEED - i; + let collator = create_funded_collator::( + "collator", + seed, + 0u32.into(), + true, + candidate_count + )?; + candidate_count += 1u32; + } + let caller: T::AccountId = create_funded_collator::( + "caller", + USER_SEED, + 0u32.into(), + true, + candidate_count, + )?; + candidate_count += 1u32; + }: _(RawOrigin::Signed(caller.clone()), candidate_count) + verify { + assert!(Pallet::::candidate_info(&caller).unwrap().is_leaving()); + } + + execute_leave_candidates { + // x is total number of delegations for the candidate + let x in 2..(<::MaxTopDelegationsPerCandidate as Get>::get() + + <::MaxBottomDelegationsPerCandidate as Get>::get()); + let candidate: T::AccountId = create_funded_collator::( + "unique_caller", + USER_SEED - 100, + 0u32.into(), + true, + 1u32, + )?; + // 2nd delegation required for all delegators to ensure DelegatorState updated not removed + let second_candidate: T::AccountId = create_funded_collator::( + "unique__caller", + USER_SEED - 99, + 0u32.into(), + true, + 2u32, + )?; + let mut delegators: Vec = Vec::new(); + let mut col_del_count = 0u32; + for i in 1..x { + let seed = USER_SEED + i; + let delegator = create_funded_delegator::( + "delegator", + seed, + min_delegator_stk::(), + candidate.clone(), + true, + col_del_count, + )?; + Pallet::::delegate( + RawOrigin::Signed(delegator.clone()).into(), + second_candidate.clone(), + min_delegator_stk::(), + col_del_count, + 1u32, + )?; + Pallet::::schedule_revoke_delegation( + RawOrigin::Signed(delegator.clone()).into(), + candidate.clone() + )?; + delegators.push(delegator); + col_del_count += 1u32; + } + Pallet::::schedule_leave_candidates( + RawOrigin::Signed(candidate.clone()).into(), + 3u32 + )?; + roll_to_and_author::(2, candidate.clone()); + }: _(RawOrigin::Signed(candidate.clone()), candidate.clone(), col_del_count) + verify { + assert!(Pallet::::candidate_info(&candidate).is_none()); + assert!(Pallet::::candidate_info(&second_candidate).is_some()); + for delegator in delegators { + assert!(Pallet::::is_delegator(&delegator)); + } + } + + cancel_leave_candidates { let x in 3..1_000; // Worst Case Complexity is removal from an ordered list so \exists full list before call let mut candidate_count = 1u32; @@ -175,6 +347,7 @@ benchmarks! { "collator", seed, 0u32.into(), + true, candidate_count )?; candidate_count += 1u32; @@ -183,12 +356,18 @@ benchmarks! { "caller", USER_SEED, 0u32.into(), + true, candidate_count, )?; candidate_count += 1u32; + Pallet::::schedule_leave_candidates( + RawOrigin::Signed(caller.clone()).into(), + candidate_count + )?; + candidate_count -= 1u32; }: _(RawOrigin::Signed(caller.clone()), candidate_count) verify { - assert!(Pallet::::collator_state2(&caller).unwrap().is_leaving()); + assert!(Pallet::::candidate_info(&caller).unwrap().is_active()); } go_offline { @@ -196,11 +375,12 @@ benchmarks! { "collator", USER_SEED, 0u32.into(), + true, 1u32 )?; }: _(RawOrigin::Signed(caller.clone())) verify { - assert!(!Pallet::::collator_state2(&caller).unwrap().is_active()); + assert!(!Pallet::::candidate_info(&caller).unwrap().is_active()); } go_online { @@ -208,155 +388,260 @@ benchmarks! { "collator", USER_SEED, 0u32.into(), + true, 1u32 )?; Pallet::::go_offline(RawOrigin::Signed(caller.clone()).into())?; }: _(RawOrigin::Signed(caller.clone())) verify { - assert!(Pallet::::collator_state2(&caller).unwrap().is_active()); + assert!(Pallet::::candidate_info(&caller).unwrap().is_active()); } candidate_bond_more { - let balance = default_balance::(); + let more = min_candidate_stk::(); let caller: T::AccountId = create_funded_collator::( "collator", USER_SEED, - balance, + more, + true, 1u32, )?; - }: _(RawOrigin::Signed(caller.clone()), balance) + }: _(RawOrigin::Signed(caller.clone()), more) verify { - let expected_bond = balance * 2u32.into(); + let expected_bond = more * 2u32.into(); assert_eq!(T::Currency::reserved_balance(&caller), expected_bond); } - candidate_bond_less { - let balance = default_balance::(); + schedule_candidate_bond_less { + let min_candidate_stk = min_candidate_stk::(); let caller: T::AccountId = create_funded_collator::( "collator", USER_SEED, - balance, + min_candidate_stk, + false, 1u32, )?; - Pallet::::candidate_bond_more(RawOrigin::Signed(caller.clone()).into(), balance)?; - }: _(RawOrigin::Signed(caller.clone()), balance) + }: _(RawOrigin::Signed(caller.clone()), min_candidate_stk) verify { - assert_eq!(T::Currency::reserved_balance(&caller), balance); + let state = Pallet::::candidate_info(&caller).expect("request bonded less so exists"); + assert_eq!( + state.request, + Some(CandidateBondLessRequest { + amount: min_candidate_stk, + when_executable: 3, + }) + ); } - nominate { - let max_nominations = <::MaxCollatorsPerNominator as Get>::get(); - let max_nominators = <::MaxNominatorsPerCollator as Get>::get(); - let x in 3..<::MaxCollatorsPerNominator as Get>::get(); - let y in 2..<::MaxNominatorsPerCollator as Get>::get(); - // Worst Case is full of nominations before calling `nominate` + execute_candidate_bond_less { + let min_candidate_stk = min_candidate_stk::(); + let caller: T::AccountId = create_funded_collator::( + "collator", + USER_SEED, + min_candidate_stk, + false, + 1u32, + )?; + Pallet::::schedule_candidate_bond_less( + RawOrigin::Signed(caller.clone()).into(), + min_candidate_stk + )?; + roll_to_and_author::(2, caller.clone()); + }: { + Pallet::::execute_candidate_bond_less( + RawOrigin::Signed(caller.clone()).into(), + caller.clone() + )?; + } verify { + assert_eq!(T::Currency::reserved_balance(&caller), min_candidate_stk); + } + + cancel_candidate_bond_less { + let min_candidate_stk = min_candidate_stk::(); + let caller: T::AccountId = create_funded_collator::( + "collator", + USER_SEED, + min_candidate_stk, + false, + 1u32, + )?; + Pallet::::schedule_candidate_bond_less( + RawOrigin::Signed(caller.clone()).into(), + min_candidate_stk + )?; + }: { + Pallet::::cancel_candidate_bond_less( + RawOrigin::Signed(caller.clone()).into(), + )?; + } verify { + assert!( + Pallet::::candidate_info(&caller).unwrap().request.is_none() + ); + } + + delegate { + let x in 3..<::MaxDelegationsPerDelegator as Get>::get(); + let y in 2..<::MaxTopDelegationsPerCandidate as Get>::get(); + // Worst Case is full of delegations before calling `delegate` let mut collators: Vec = Vec::new(); - // Initialize MaxCollatorsPerNominator collator candidates + // Initialize MaxDelegationsPerDelegator collator candidates for i in 2..x { let seed = USER_SEED - i; let collator = create_funded_collator::( "collator", seed, 0u32.into(), + true, collators.len() as u32 + 1u32, )?; collators.push(collator.clone()); } - let bond = <::MinNominatorStk as Get>>::get(); - let extra = if (bond * (collators.len() as u32 + 1u32).into()) > default_balance::() { - (bond * (collators.len() as u32 + 1u32).into()) - default_balance::() + let bond = <::MinDelegatorStk as Get>>::get(); + let extra = if (bond * (collators.len() as u32 + 1u32).into()) > min_candidate_stk::() { + (bond * (collators.len() as u32 + 1u32).into()) - min_candidate_stk::() } else { 0u32.into() }; - let caller: T::AccountId = create_funded_user::("caller", USER_SEED, extra.into()); - // Nomination count - let mut nom_nom_count = 0u32; - // Nominate MaxCollatorsPerNominators collator candidates + let (caller, _) = create_funded_user::("caller", USER_SEED, extra.into()); + // Delegation count + let mut del_del_count = 0u32; + // Nominate MaxDelegationsPerDelegators collator candidates for col in collators.clone() { - Pallet::::nominate( - RawOrigin::Signed(caller.clone()).into(), col, bond, 0u32, nom_nom_count + Pallet::::delegate( + RawOrigin::Signed(caller.clone()).into(), col, bond, 0u32, del_del_count )?; - nom_nom_count += 1u32; + del_del_count += 1u32; } - // Last collator to be nominated + // Last collator to be delegated let collator: T::AccountId = create_funded_collator::( "collator", USER_SEED, 0u32.into(), + true, collators.len() as u32 + 1u32, )?; // Worst Case Complexity is insertion into an almost full collator - let mut col_nom_count = 0u32; + let mut col_del_count = 0u32; for i in 1..y { let seed = USER_SEED + i; - let nominator = create_funded_nominator::( - "nominator", + let _ = create_funded_delegator::( + "delegator", seed, 0u32.into(), collator.clone(), - col_nom_count, + true, + col_del_count, )?; - col_nom_count += 1u32; + col_del_count += 1u32; } - }: _(RawOrigin::Signed(caller.clone()), collator, bond, col_nom_count, nom_nom_count) + }: _(RawOrigin::Signed(caller.clone()), collator, bond, col_del_count, del_del_count) verify { - assert!(Pallet::::is_nominator(&caller)); + assert!(Pallet::::is_delegator(&caller)); } - leave_nominators { - let x in 2..<::MaxCollatorsPerNominator as Get>::get(); - // Worst Case is full of nominations before exit + schedule_leave_delegators { + let collator: T::AccountId = create_funded_collator::( + "collator", + USER_SEED, + 0u32.into(), + true, + 1u32 + )?; + let (caller, _) = create_funded_user::("caller", USER_SEED, 0u32.into()); + let bond = <::MinDelegatorStk as Get>>::get(); + Pallet::::delegate(RawOrigin::Signed( + caller.clone()).into(), + collator.clone(), + bond, + 0u32, + 0u32 + )?; + }: _(RawOrigin::Signed(caller.clone())) + verify { + assert!(Pallet::::delegator_state(&caller).unwrap().is_leaving()); + } + + execute_leave_delegators { + let x in 2..<::MaxDelegationsPerDelegator as Get>::get(); + // Worst Case is full of delegations before execute exit let mut collators: Vec = Vec::new(); - // Initialize MaxCollatorsPerNominator collator candidates + // Initialize MaxDelegationsPerDelegator collator candidates for i in 1..x { let seed = USER_SEED - i; let collator = create_funded_collator::( "collator", seed, 0u32.into(), + true, collators.len() as u32 + 1u32 )?; collators.push(collator.clone()); } - let bond = <::MinNominatorStk as Get>>::get(); + let bond = <::MinDelegatorStk as Get>>::get(); let need = bond * (collators.len() as u32).into(); - let default_minted = default_balance::(); + let default_minted = min_candidate_stk::(); let need: BalanceOf = if need > default_minted { need - default_minted } else { 0u32.into() }; - // Fund the nominator - let caller: T::AccountId = create_funded_user::("caller", USER_SEED, need); - let nomination_count = collators.len() as u32; - // Nomination count - let mut nom_count = 0u32; - // Nominate MaxCollatorsPerNominators collator candidates + // Fund the delegator + let (caller, _) = create_funded_user::("caller", USER_SEED, need); + // Delegation count + let mut delegation_count = 0u32; + let author = collators[0].clone(); + // Nominate MaxDelegationsPerDelegators collator candidates for col in collators { - Pallet::::nominate( + Pallet::::delegate( RawOrigin::Signed(caller.clone()).into(), col, bond, 0u32, - nom_count + delegation_count )?; - nom_count += 1u32; + delegation_count += 1u32; } - }: _(RawOrigin::Signed(caller.clone()), nomination_count) + Pallet::::schedule_leave_delegators(RawOrigin::Signed(caller.clone()).into())?; + roll_to_and_author::(2, author); + }: _(RawOrigin::Signed(caller.clone()), caller.clone(), delegation_count) verify { - assert!(Pallet::::nominator_state2(&caller).unwrap().is_leaving()); + assert!(Pallet::::delegator_state(&caller).is_none()); } - revoke_nomination { + cancel_leave_delegators { let collator: T::AccountId = create_funded_collator::( "collator", USER_SEED, 0u32.into(), + true, 1u32 )?; - let caller: T::AccountId = create_funded_user::("caller", USER_SEED, 0u32.into()); - let bond = <::MinNominatorStk as Get>>::get(); - Pallet::::nominate(RawOrigin::Signed( + let (caller, _) = create_funded_user::("caller", USER_SEED, 0u32.into()); + let bond = <::MinDelegatorStk as Get>>::get(); + Pallet::::delegate(RawOrigin::Signed( + caller.clone()).into(), + collator.clone(), + bond, + 0u32, + 0u32 + )?; + Pallet::::schedule_leave_delegators(RawOrigin::Signed(caller.clone()).into())?; + }: _(RawOrigin::Signed(caller.clone())) + verify { + assert!(Pallet::::delegator_state(&caller).unwrap().is_active()); + } + + schedule_revoke_delegation { + let collator: T::AccountId = create_funded_collator::( + "collator", + USER_SEED, + 0u32.into(), + true, + 1u32 + )?; + let (caller, _) = create_funded_user::("caller", USER_SEED, 0u32.into()); + let bond = <::MinDelegatorStk as Get>>::get(); + Pallet::::delegate(RawOrigin::Signed( caller.clone()).into(), collator.clone(), bond, @@ -366,68 +651,221 @@ benchmarks! { }: _(RawOrigin::Signed(caller.clone()), collator.clone()) verify { assert_eq!( - Pallet::::nominator_state2(&caller).unwrap().revocations.0[0], - collator + Pallet::::delegator_state(&caller).unwrap().requests().get(&collator), + Some(&DelegationRequest { + collator, + amount: bond, + when_executable: 3, + action: DelegationChange::Revoke + }) ); } - nominator_bond_more { + delegator_bond_more { let collator: T::AccountId = create_funded_collator::( "collator", USER_SEED, 0u32.into(), + true, 1u32 )?; - let caller: T::AccountId = create_funded_user::("caller", USER_SEED, 0u32.into()); - let bond = <::MinNominatorStk as Get>>::get(); - Pallet::::nominate( + let (caller, _) = create_funded_user::("caller", USER_SEED, 0u32.into()); + let bond = <::MinDelegatorStk as Get>>::get(); + Pallet::::delegate( RawOrigin::Signed(caller.clone()).into(), collator.clone(), bond, 0u32, 0u32 )?; - }: _(RawOrigin::Signed(caller.clone()), collator, bond) + }: _(RawOrigin::Signed(caller.clone()), collator.clone(), bond) verify { let expected_bond = bond * 2u32.into(); assert_eq!(T::Currency::reserved_balance(&caller), expected_bond); } - nominator_bond_less { + schedule_delegator_bond_less { let collator: T::AccountId = create_funded_collator::( "collator", USER_SEED, 0u32.into(), + true, 1u32 )?; - let caller: T::AccountId = create_funded_user::("caller", USER_SEED, 0u32.into()); - let total = default_balance::(); - Pallet::::nominate(RawOrigin::Signed( + let (caller, total) = create_funded_user::("caller", USER_SEED, 0u32.into()); + Pallet::::delegate(RawOrigin::Signed( caller.clone()).into(), collator.clone(), total, 0u32, 0u32 )?; - let bond_less = <::MinNominatorStk as Get>>::get(); - }: _(RawOrigin::Signed(caller.clone()), collator, bond_less) + let bond_less = <::MinDelegatorStk as Get>>::get(); + }: _(RawOrigin::Signed(caller.clone()), collator.clone(), bond_less) verify { + let state = Pallet::::delegator_state(&caller) + .expect("just request bonded less so exists"); + assert_eq!( + state.requests().get(&collator), + Some(&DelegationRequest { + collator, + amount: 5u32.into(), + when_executable: 3, + action: DelegationChange::Decrease + }) + ); + } + + execute_revoke_delegation { + let collator: T::AccountId = create_funded_collator::( + "collator", + USER_SEED, + 0u32.into(), + true, + 1u32 + )?; + let (caller, _) = create_funded_user::("caller", USER_SEED, 0u32.into()); + let bond = <::MinDelegatorStk as Get>>::get(); + Pallet::::delegate(RawOrigin::Signed( + caller.clone()).into(), + collator.clone(), + bond, + 0u32, + 0u32 + )?; + Pallet::::schedule_revoke_delegation(RawOrigin::Signed( + caller.clone()).into(), + collator.clone() + )?; + roll_to_and_author::(2, collator.clone()); + }: { + Pallet::::execute_delegation_request( + RawOrigin::Signed(caller.clone()).into(), + caller.clone(), + collator.clone() + )?; + } verify { + assert!( + !Pallet::::is_delegator(&caller) + ); + } + + execute_delegator_bond_less { + let collator: T::AccountId = create_funded_collator::( + "collator", + USER_SEED, + 0u32.into(), + true, + 1u32 + )?; + let (caller, total) = create_funded_user::("caller", USER_SEED, 0u32.into()); + Pallet::::delegate(RawOrigin::Signed( + caller.clone()).into(), + collator.clone(), + total, + 0u32, + 0u32 + )?; + let bond_less = <::MinDelegatorStk as Get>>::get(); + Pallet::::schedule_delegator_bond_less( + RawOrigin::Signed(caller.clone()).into(), + collator.clone(), + bond_less + )?; + roll_to_and_author::(2, collator.clone()); + }: { + Pallet::::execute_delegation_request( + RawOrigin::Signed(caller.clone()).into(), + caller.clone(), + collator.clone() + )?; + } verify { let expected = total - bond_less; assert_eq!(T::Currency::reserved_balance(&caller), expected); } + cancel_revoke_delegation { + let collator: T::AccountId = create_funded_collator::( + "collator", + USER_SEED, + 0u32.into(), + true, + 1u32 + )?; + let (caller, _) = create_funded_user::("caller", USER_SEED, 0u32.into()); + let bond = <::MinDelegatorStk as Get>>::get(); + Pallet::::delegate(RawOrigin::Signed( + caller.clone()).into(), + collator.clone(), + bond, + 0u32, + 0u32 + )?; + Pallet::::schedule_revoke_delegation( + RawOrigin::Signed(caller.clone()).into(), + collator.clone() + )?; + }: { + Pallet::::cancel_delegation_request( + RawOrigin::Signed(caller.clone()).into(), + collator.clone() + )?; + } verify { + assert!( + Pallet::::delegator_state(&caller).unwrap().requests().get(&collator).is_none() + ); + } + + cancel_delegator_bond_less { + let collator: T::AccountId = create_funded_collator::( + "collator", + USER_SEED, + 0u32.into(), + true, + 1u32 + )?; + let (caller, total) = create_funded_user::("caller", USER_SEED, 0u32.into()); + Pallet::::delegate(RawOrigin::Signed( + caller.clone()).into(), + collator.clone(), + total, + 0u32, + 0u32 + )?; + let bond_less = <::MinDelegatorStk as Get>>::get(); + Pallet::::schedule_delegator_bond_less( + RawOrigin::Signed(caller.clone()).into(), + collator.clone(), + bond_less + )?; + roll_to_and_author::(2, collator.clone()); + }: { + Pallet::::cancel_delegation_request( + RawOrigin::Signed(caller.clone()).into(), + collator.clone() + )?; + } verify { + assert!( + Pallet::::delegator_state(&caller) + .unwrap() + .requests() + .get(&collator) + .is_none() + ); + } + // ON_INITIALIZE - active_on_initialize { + round_transition_on_initialize { // TOTAL SELECTED COLLATORS PER ROUND let x in 1..28; - // NOMINATIONS - let y in 0..(<::MaxNominatorsPerCollator as Get>::get() * 28); - let max_nominators_per_collator = - <::MaxNominatorsPerCollator as Get>::get(); - let max_nominations = x * max_nominators_per_collator; + // DELEGATIONS + let y in 0..(<::MaxTopDelegationsPerCandidate as Get>::get() * 28); + let max_delegators_per_collator = + <::MaxTopDelegationsPerCandidate as Get>::get(); + let max_delegations = x * max_delegators_per_collator; // y should depend on x but cannot directly, we overwrite y here if necessary to bound it - let total_nominations: u32 = if max_nominations < y { max_nominations } else { y }; + let total_delegations: u32 = if max_delegations < y { max_delegations } else { y }; // INITIALIZE RUNTIME STATE let high_inflation: Range = Range { min: Perbill::one(), @@ -444,7 +882,8 @@ benchmarks! { let collator = create_funded_collator::( "collator", seed, - default_balance::() * 1_000_000u32.into(), + min_candidate_stk::() * 1_000_000u32.into(), + true, collator_count )?; collators.push(collator); @@ -455,71 +894,73 @@ benchmarks! { T::AccountId, <::Currency as Currency>::Balance )> = collators.iter().map(|x| (x.clone(), T::Currency::free_balance(&x))).collect(); - // INITIALIZE NOMINATIONS - let mut col_nom_count: BTreeMap = BTreeMap::new(); + // INITIALIZE DELEGATIONS + let mut col_del_count: BTreeMap = BTreeMap::new(); collators.iter().for_each(|x| { - col_nom_count.insert(x.clone(), 0u32); + col_del_count.insert(x.clone(), 0u32); }); - let mut nominators: Vec = Vec::new(); - let mut remaining_nominations = if total_nominations > max_nominators_per_collator { - for j in 1..(max_nominators_per_collator + 1) { + let mut delegators: Vec = Vec::new(); + let mut remaining_delegations = if total_delegations > max_delegators_per_collator { + for j in 1..(max_delegators_per_collator + 1) { let seed = USER_SEED + j; - let nominator = create_funded_nominator::( - "nominator", + let delegator = create_funded_delegator::( + "delegator", seed, - default_balance::() * 1_000_000u32.into(), + min_candidate_stk::() * 1_000_000u32.into(), collators[0].clone(), - nominators.len() as u32, + true, + delegators.len() as u32, )?; - nominators.push(nominator); + delegators.push(delegator); } - total_nominations - max_nominators_per_collator + total_delegations - max_delegators_per_collator } else { - for j in 1..(total_nominations + 1) { + for j in 1..(total_delegations + 1) { let seed = USER_SEED + j; - let nominator = create_funded_nominator::( - "nominator", + let delegator = create_funded_delegator::( + "delegator", seed, - default_balance::() * 1_000_000u32.into(), + min_candidate_stk::() * 1_000_000u32.into(), collators[0].clone(), - nominators.len() as u32, + true, + delegators.len() as u32, )?; - nominators.push(nominator); + delegators.push(delegator); } 0u32 }; - col_nom_count.insert(collators[0].clone(), nominators.len() as u32); - // FILL remaining nominations - if remaining_nominations > 0 { - for (col, n_count) in col_nom_count.iter_mut() { - if n_count < &mut (nominators.len() as u32) { - // assumes nominators.len() <= MaxNominatorsPerCollator - let mut open_spots = nominators.len() as u32 - *n_count; - while open_spots > 0 && remaining_nominations > 0 { - let caller = nominators[open_spots as usize - 1usize].clone(); - if let Ok(_) = Pallet::::nominate(RawOrigin::Signed( + col_del_count.insert(collators[0].clone(), delegators.len() as u32); + // FILL remaining delegations + if remaining_delegations > 0 { + for (col, n_count) in col_del_count.iter_mut() { + if n_count < &mut (delegators.len() as u32) { + // assumes delegators.len() <= MaxTopDelegationsPerCandidate + let mut open_spots = delegators.len() as u32 - *n_count; + while open_spots > 0 && remaining_delegations > 0 { + let caller = delegators[open_spots as usize - 1usize].clone(); + if let Ok(_) = Pallet::::delegate(RawOrigin::Signed( caller.clone()).into(), col.clone(), - <::MinNominatorStk as Get>>::get(), + <::MinDelegatorStk as Get>>::get(), *n_count, collators.len() as u32, // overestimate ) { *n_count += 1; - remaining_nominations -= 1; + remaining_delegations -= 1; } open_spots -= 1; } } - if remaining_nominations == 0 { + if remaining_delegations == 0 { break; } } } - // STORE starting balances for all nominators - let nominator_starting_balances: Vec<( + // STORE starting balances for all delegators + let delegator_starting_balances: Vec<( T::AccountId, <::Currency as Currency>::Balance - )> = nominators.iter().map(|x| (x.clone(), T::Currency::free_balance(&x))).collect(); + )> = delegators.iter().map(|x| (x.clone(), T::Currency::free_balance(&x))).collect(); // PREPARE RUN_TO_BLOCK LOOP let before_running_round_index = Pallet::::round().current; let round_length: T::BlockNumber = Pallet::::round().length.into(); @@ -553,18 +994,114 @@ benchmarks! { assert!(T::Currency::free_balance(&col) > initial); } // Nominators have been paid - for (col, initial) in nominator_starting_balances { + for (col, initial) in delegator_starting_balances { assert!(T::Currency::free_balance(&col) > initial); } // Round transitions assert_eq!(Pallet::::round().current, before_running_round_index + reward_delay); } - passive_on_initialize { + pay_one_collator_reward { + // y controls number of delegators + // TODO: mock.rs sets MaxTopDelegationsPerCandidate to 4, which is too low for this test to be + // meaningful. we use a higher value here, which works so long as we don't invoke any of + // pallet_staking's logic which uses MaxTopDelegationsPerCandidate as a constraint. this is + // brittle, to say the least... + let y in 0..2000; + + // must come after 'let foo in 0..` statements for macro + use crate::{ + DelayedPayout, DelayedPayouts, AtStake, CollatorSnapshot, Bond, Points, + AwardedPts, + }; + + let before_running_round_index = Pallet::::round().current; + let initial_stake_amount = min_candidate_stk::() * 1_000_000u32.into(); + + let mut total_staked = 0u32.into(); + + // initialize our single collator + let sole_collator = create_funded_collator::( + "collator", + 0, + initial_stake_amount, + true, + 1u32, + )?; + total_staked += initial_stake_amount; + + // generate funded collator accounts + let mut delegators: Vec = Vec::new(); + for i in 0..y { + let seed = USER_SEED + i; + let delegator = create_funded_delegator::( + "delegator", + seed, + initial_stake_amount, + sole_collator.clone(), + true, + delegators.len() as u32, + )?; + delegators.push(delegator); + total_staked += initial_stake_amount; + } + + // rather than roll through rounds in order to initialize the storage we want, we set it + // directly and then call pay_one_collator_reward directly. + + let round_for_payout = 5; + >::insert(&round_for_payout, DelayedPayout { + // NOTE: round_issuance is not correct here, but it doesn't seem to cause problems + round_issuance: 1000u32.into(), + total_staking_reward: total_staked, + collator_commission: Perbill::from_rational(1u32, 100u32), + }); + + let mut delegations: Vec>> = Vec::new(); + for delegator in &delegators { + delegations.push(Bond { + owner: delegator.clone(), + amount: 100u32.into(), + }); + } + + >::insert(round_for_payout, &sole_collator, CollatorSnapshot { + bond: 1_000u32.into(), + delegations, + total: 1_000_000u32.into(), + }); + + >::insert(round_for_payout, 100); + >::insert(round_for_payout, &sole_collator, 20); + + }: { + let round_for_payout = 5; + // TODO: this is an extra read right here (we should whitelist it?) + let payout_info = Pallet::::delayed_payouts(round_for_payout).expect("payout expected"); + let result = Pallet::::pay_one_collator_reward(round_for_payout, payout_info); + assert!(result.0.is_some()); // TODO: how to keep this in scope so it can be done in verify block? + } + verify { + // collator should have been paid + assert!( + T::Currency::free_balance(&sole_collator) > initial_stake_amount, + "collator should have been paid in pay_one_collator_reward" + ); + // nominators should have been paid + for delegator in &delegators { + assert!( + T::Currency::free_balance(&delegator) > initial_stake_amount, + "delegator should have been paid in pay_one_collator_reward" + ); + } + } + + base_on_initialize { let collator: T::AccountId = create_funded_collator::( "collator", USER_SEED, 0u32.into(), + true, 1u32 )?; let start = >::block_number(); @@ -596,143 +1133,227 @@ mod tests { TestExternalities::new(t) } + #[test] + fn bench_hotfix_remove_delegation_requests() { + new_test_ext().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_hotfix_remove_delegation_requests()); + }); + } + + #[test] + fn bench_hotfix_update_candidate_pool_value() { + new_test_ext().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_hotfix_update_candidate_pool_value()); + }); + } + #[test] fn bench_set_staking_expectations() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_set_staking_expectations::()); + assert_ok!(Pallet::::test_benchmark_set_staking_expectations()); }); } #[test] fn bench_set_inflation() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_set_inflation::()); + assert_ok!(Pallet::::test_benchmark_set_inflation()); }); } #[test] fn bench_set_parachain_bond_account() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_set_parachain_bond_account::()); + assert_ok!(Pallet::::test_benchmark_set_parachain_bond_account()); }); } #[test] fn bench_set_parachain_bond_reserve_percent() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_set_parachain_bond_reserve_percent::()); + assert_ok!(Pallet::::test_benchmark_set_parachain_bond_reserve_percent()); }); } #[test] fn bench_set_total_selected() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_set_total_selected::()); + assert_ok!(Pallet::::test_benchmark_set_total_selected()); }); } #[test] fn bench_set_collator_commission() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_set_collator_commission::()); + assert_ok!(Pallet::::test_benchmark_set_collator_commission()); }); } #[test] fn bench_set_blocks_per_round() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_set_blocks_per_round::()); + assert_ok!(Pallet::::test_benchmark_set_blocks_per_round()); }); } #[test] fn bench_join_candidates() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_join_candidates::()); + assert_ok!(Pallet::::test_benchmark_join_candidates()); + }); + } + + #[test] + fn bench_schedule_leave_candidates() { + new_test_ext().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_schedule_leave_candidates()); }); } #[test] - fn bench_leave_candidates() { + fn bench_execute_leave_candidates() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_leave_candidates::()); + assert_ok!(Pallet::::test_benchmark_execute_leave_candidates()); + }); + } + + #[test] + fn bench_cancel_leave_candidates() { + new_test_ext().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_cancel_leave_candidates()); }); } #[test] fn bench_go_offline() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_go_offline::()); + assert_ok!(Pallet::::test_benchmark_go_offline()); }); } #[test] fn bench_go_online() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_go_online::()); + assert_ok!(Pallet::::test_benchmark_go_online()); }); } #[test] fn bench_candidate_bond_more() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_candidate_bond_more::()); + assert_ok!(Pallet::::test_benchmark_candidate_bond_more()); + }); + } + + #[test] + fn bench_schedule_candidate_bond_less() { + new_test_ext().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_schedule_candidate_bond_less()); + }); + } + + #[test] + fn bench_execute_candidate_bond_less() { + new_test_ext().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_execute_candidate_bond_less()); + }); + } + + #[test] + fn bench_cancel_candidate_bond_less() { + new_test_ext().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_cancel_candidate_bond_less()); + }); + } + + #[test] + fn bench_delegate() { + new_test_ext().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_delegate()); + }); + } + + #[test] + fn bench_schedule_leave_delegators() { + new_test_ext().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_schedule_leave_delegators()); + }); + } + + #[test] + fn bench_execute_leave_delegators() { + new_test_ext().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_execute_leave_delegators()); + }); + } + + #[test] + fn bench_cancel_leave_delegators() { + new_test_ext().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_cancel_leave_delegators()); + }); + } + + #[test] + fn bench_schedule_revoke_delegation() { + new_test_ext().execute_with(|| { + assert_ok!(Pallet::::test_benchmark_schedule_revoke_delegation()); }); } #[test] - fn bench_candidate_bond_less() { + fn bench_delegator_bond_more() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_candidate_bond_less::()); + assert_ok!(Pallet::::test_benchmark_delegator_bond_more()); }); } #[test] - fn bench_nominate() { + fn bench_schedule_delegator_bond_less() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_nominate::()); + assert_ok!(Pallet::::test_benchmark_schedule_delegator_bond_less()); }); } #[test] - fn bench_leave_nominators() { + fn bench_execute_revoke_delegation() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_leave_nominators::()); + assert_ok!(Pallet::::test_benchmark_execute_revoke_delegation()); }); } #[test] - fn bench_revoke_nomination() { + fn bench_execute_delegator_bond_less() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_revoke_nomination::()); + assert_ok!(Pallet::::test_benchmark_execute_delegator_bond_less()); }); } #[test] - fn bench_nominator_bond_more() { + fn bench_cancel_revoke_delegation() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_nominator_bond_more::()); + assert_ok!(Pallet::::test_benchmark_cancel_revoke_delegation()); }); } #[test] - fn bench_nominator_bond_less() { + fn bench_cancel_delegator_bond_less() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_nominator_bond_less::()); + assert_ok!(Pallet::::test_benchmark_cancel_delegator_bond_less()); }); } #[test] - fn bench_active_on_initialize() { + fn bench_round_transition_on_initialize() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_active_on_initialize::()); + assert_ok!(Pallet::::test_benchmark_round_transition_on_initialize()); }); } #[test] - fn bench_passive_on_initialize() { + fn bench_base_on_initialize() { new_test_ext().execute_with(|| { - assert_ok!(test_benchmark_passive_on_initialize::()); + assert_ok!(Pallet::::test_benchmark_base_on_initialize()); }); } } diff --git a/pallets/parachain-staking/src/inflation.rs b/pallets/parachain-staking/src/inflation.rs index 23f7fcd6..5df689b0 100644 --- a/pallets/parachain-staking/src/inflation.rs +++ b/pallets/parachain-staking/src/inflation.rs @@ -1,4 +1,4 @@ -// Copyright 2019-2021 PureStake Inc. +// Copyright 2019-2022 PureStake Inc. // This file is part of Moonbeam. // Moonbeam is free software: you can redistribute it and/or modify @@ -17,7 +17,7 @@ //! Helper methods for computing issuance based on inflation use crate::pallet::{BalanceOf, Config, Pallet}; use frame_support::traits::Currency; -use parity_scale_codec::{Decode, Encode}; +use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; @@ -28,7 +28,7 @@ use substrate_fixed::types::{I32F32, I64F64}; const SECONDS_PER_YEAR: u32 = 31557600; const SECONDS_PER_BLOCK: u32 = 12; -const BLOCKS_PER_YEAR: u32 = SECONDS_PER_YEAR / SECONDS_PER_BLOCK; +pub const BLOCKS_PER_YEAR: u32 = SECONDS_PER_YEAR / SECONDS_PER_BLOCK; fn rounds_per_year() -> u32 { let blocks_per_round = >::round().length; @@ -36,7 +36,9 @@ fn rounds_per_year() -> u32 { } #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -#[derive(Eq, PartialEq, Clone, Copy, Encode, Decode, Default, RuntimeDebug, TypeInfo)] +#[derive( + Eq, PartialEq, Clone, Copy, Encode, Decode, Default, RuntimeDebug, MaxEncodedLen, TypeInfo, +)] pub struct Range { pub min: T, pub ideal: T, @@ -59,8 +61,8 @@ impl From for Range { } } /// Convert an annual inflation to a round inflation -/// round = 1 - (1+annual)^(1/rounds_per_year) -fn perbill_annual_to_perbill_round( +/// round = (1+annual)^(1/rounds_per_year) - 1 +pub fn perbill_annual_to_perbill_round( annual: Range, rounds_per_year: u32, ) -> Range { diff --git a/pallets/parachain-staking/src/lib.rs b/pallets/parachain-staking/src/lib.rs index b4c72cfb..7e511c5d 100644 --- a/pallets/parachain-staking/src/lib.rs +++ b/pallets/parachain-staking/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2019-2021 PureStake Inc. +// Copyright 2019-2022 PureStake Inc. // This file is part of Moonbeam. // Moonbeam is free software: you can redistribute it and/or modify @@ -17,49 +17,51 @@ //! # Parachain Staking //! Minimal staking pallet that implements collator selection by total backed stake. //! The main difference between this pallet and `frame/pallet-staking` is that this pallet -//! uses direct delegation. Nominators choose exactly who they nominate and with what stake. -//! This is different from `frame/pallet-staking` where you approval vote and then run Phragmen. +//! uses direct delegation. Delegators choose exactly who they delegate and with what stake. +//! This is different from `frame/pallet-staking` where delegators approval vote and run Phragmen. //! //! ### Rules //! There is a new round every `>::get().length` blocks. //! //! At the start of every round, -//! * issuance is distributed to collators (and their nominators) for block authoring +//! * issuance is calculated for collators (and their delegators) for block authoring //! `T::RewardPaymentDelay` rounds ago -//! * queued collator and nominator exits are executed //! * a new set of collators is chosen from the candidates //! -//! To join the set of candidates, call `join_candidates` with `bond >= MinCollatorCandidateStk`. +//! Immediately following a round change, payments are made once-per-block until all payments have +//! been made. In each such block, one collator is chosen for a rewards payment and is paid along +//! with each of its top `T::MaxTopDelegationsPerCandidate` delegators. //! -//! To leave the set of candidates, call `leave_candidates`. If the call succeeds, +//! To join the set of candidates, call `join_candidates` with `bond >= MinCandidateStk`. +//! To leave the set of candidates, call `schedule_leave_candidates`. If the call succeeds, //! the collator is removed from the pool of candidates so they cannot be selected for future -//! collator sets, but they are not unstaked until `T::LeaveCandidatesDelay` rounds later. -//! The exit request is stored in the `ExitQueue` and processed `T::LeaveCandidatesDelay` rounds -//! later to unstake the collator and all of its nominations. +//! collator sets, but they are not unbonded until their exit request is executed. Any signed +//! account may trigger the exit `T::LeaveCandidatesDelay` rounds after the round in which the +//! original request was made. //! -//! To join the set of nominators, call `nominate` and pass in an account that is -//! already a collator candidate and `bond >= MinNominatorStk`. Each nominator can nominate up to -//! `T::MaxCollatorsPerNominator` collator candidates by calling `nominate`. +//! To join the set of delegators, call `delegate` and pass in an account that is +//! already a collator candidate and `bond >= MinDelegatorStk`. Each delegator can delegate up to +//! `T::MaxDelegationsPerDelegator` collator candidates by calling `delegate`. //! -//! To revoke a nomination, call `revoke_nomination` with the collator candidate's account. -//! To leave the set of nominators and revoke all nominations, call `leave_nominators`. +//! To revoke a delegation, call `revoke_delegation` with the collator candidate's account. +//! To leave the set of delegators and revoke all delegations, call `leave_delegators`. #![cfg_attr(not(feature = "std"), no_std)] #[cfg(any(test, feature = "runtime-benchmarks"))] mod benchmarks; -mod inflation; +pub mod inflation; +pub mod migrations; #[cfg(test)] mod mock; mod set; #[cfg(test)] mod tests; - pub mod weights; -use weights::WeightInfo; use frame_support::pallet; pub use inflation::{InflationInfo, Range}; +use weights::WeightInfo; pub use pallet::*; @@ -79,14 +81,25 @@ pub mod pallet { /// Pallet for parachain staking #[pallet::pallet] + #[pallet::without_storage_info] pub struct Pallet(PhantomData); - #[derive(Default, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct Bond { pub owner: AccountId, pub amount: Balance, } + impl Default for Bond { + fn default() -> Bond { + Bond { + owner: A::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()) + .expect("infinite length input; no invalid inputs for type; qed"), + amount: B::default(), + } + } + } + impl Bond { fn from_owner(owner: A) -> Self { Bond { @@ -133,16 +146,38 @@ pub mod pallet { } } - #[derive(Default, Encode, Decode, RuntimeDebug, TypeInfo)] + #[derive(Encode, Decode, RuntimeDebug, TypeInfo)] /// Snapshot of collator state at the start of the round for which they are selected pub struct CollatorSnapshot { pub bond: Balance, - pub nominators: Vec>, + pub delegations: Vec>, pub total: Balance, } + impl Default for CollatorSnapshot { + fn default() -> CollatorSnapshot { + CollatorSnapshot { + bond: B::default(), + delegations: Vec::new(), + total: B::default(), + } + } + } + + #[derive(Default, Encode, Decode, RuntimeDebug, TypeInfo)] + /// Info needed to make delayed payments to stakers after round end + pub struct DelayedPayout { + /// Total round reward (result of compute_issuance() at round end) + pub round_issuance: Balance, + /// The total inflation paid this round to stakers (e.g. less parachain bond fund) + pub total_staking_reward: Balance, + /// Snapshot of collator commission rate at the end of the round + pub collator_commission: Perbill, + } + #[derive(Encode, Decode, RuntimeDebug, TypeInfo)] - /// Collator state with commission fee, bonded stake, and nominations + /// DEPRECATED + /// Collator state with commission fee, bonded stake, and delegations pub struct Collator2 { /// The account of this collator pub id: AccountId, @@ -150,338 +185,1090 @@ pub mod pallet { pub bond: Balance, /// Set of all nominator AccountIds (to prevent >1 nomination per AccountId) pub nominators: OrderedSet, - /// Top T::MaxNominatorsPerCollator::get() nominators, ordered greatest to least + /// Top T::MaxDelegatorsPerCollator::get() nominators, ordered greatest to least pub top_nominators: Vec>, /// Bottom nominators (unbounded), ordered least to greatest pub bottom_nominators: Vec>, - /// Sum of top nominations + self.bond + /// Sum of top delegations + self.bond pub total_counted: Balance, - /// Sum of all nominations + self.bond = (total_counted + uncounted) + /// Sum of all delegations + self.bond = (total_counted + uncounted) pub total_backing: Balance, /// Current status of the collator pub state: CollatorStatus, } - /// Convey relevant information describing if a nominator was added to the top or bottom - /// Nominations added to the top yield a new total - #[derive(Clone, Copy, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] - pub enum NominatorAdded { - AddedToTop { new_total: B }, - AddedToBottom, + impl From> for CollatorCandidate { + fn from(other: Collator2) -> CollatorCandidate { + CollatorCandidate { + id: other.id, + bond: other.bond, + delegators: other.nominators, + top_delegations: other.top_nominators, + bottom_delegations: other.bottom_nominators, + total_counted: other.total_counted, + total_backing: other.total_backing, + request: None, + state: other.state, + } + } + } + + #[derive(PartialEq, Clone, Copy, Encode, Decode, RuntimeDebug, TypeInfo)] + /// Request scheduled to change the collator candidate self-bond + pub struct CandidateBondLessRequest { + pub amount: Balance, + pub when_executable: RoundIndex, + } + + #[derive(Encode, Decode, RuntimeDebug, TypeInfo)] + /// DEPRECATED, replaced by `CandidateMetadata` and two storage instances of `Delegations` + /// Collator candidate state with self bond + delegations + pub struct CollatorCandidate { + /// The account of this collator + pub id: AccountId, + /// This collator's self stake. + pub bond: Balance, + /// Set of all delegator AccountIds (to prevent >1 delegation per AccountId) + pub delegators: OrderedSet, + /// Top T::MaxDelegatorsPerCollator::get() delegations, ordered greatest to least + pub top_delegations: Vec>, + /// Bottom delegations (unbounded), ordered least to greatest + pub bottom_delegations: Vec>, + /// Sum of top delegations + self.bond + pub total_counted: Balance, + /// Sum of all delegations + self.bond = (total_counted + uncounted) + pub total_backing: Balance, + /// Maximum 1 pending request to decrease candidate self bond at any given time + pub request: Option>, + /// Current status of the collator + pub state: CollatorStatus, + } + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo)] + /// Type for top and bottom delegation storage item + pub struct Delegations { + pub delegations: Vec>, + pub total: Balance, + } + + impl Default for Delegations { + fn default() -> Delegations { + Delegations { + delegations: Vec::new(), + total: B::default(), + } + } + } + + impl + Delegations + { + pub fn sort_greatest_to_least(&mut self) { + self.delegations.sort_by(|a, b| b.amount.cmp(&a.amount)); + } + /// Insert sorted greatest to least and increase .total accordingly + /// Insertion respects first come first serve so new delegations are pushed after existing + /// delegations if the amount is the same + pub fn insert_sorted_greatest_to_least(&mut self, delegation: Bond) { + self.total = self.total.saturating_add(delegation.amount); + // if delegations nonempty && last_element == delegation.amount => push input and return + if !self.delegations.is_empty() { + // if last_element == delegation.amount => push the delegation and return early + if self.delegations[self.delegations.len() - 1].amount == delegation.amount { + self.delegations.push(delegation); + // early return + return; + } + } + // else binary search insertion + match self + .delegations + .binary_search_by(|x| delegation.amount.cmp(&x.amount)) + { + // sorted insertion on sorted vec + // enforces first come first serve for equal bond amounts + Ok(i) => { + let mut new_index = i + 1; + while new_index <= (self.delegations.len() - 1) { + if self.delegations[new_index].amount == delegation.amount { + new_index += 1; + } else { + self.delegations.insert(new_index, delegation); + return; + } + } + self.delegations.push(delegation) + } + Err(i) => self.delegations.insert(i, delegation), + } + } + /// Return the capacity status for top delegations + pub fn top_capacity(&self) -> CapacityStatus { + match &self.delegations { + x if x.len() as u32 >= T::MaxTopDelegationsPerCandidate::get() => { + CapacityStatus::Full + } + x if x.is_empty() => CapacityStatus::Empty, + _ => CapacityStatus::Partial, + } + } + /// Return the capacity status for bottom delegations + pub fn bottom_capacity(&self) -> CapacityStatus { + match &self.delegations { + x if x.len() as u32 >= T::MaxBottomDelegationsPerCandidate::get() => { + CapacityStatus::Full + } + x if x.is_empty() => CapacityStatus::Empty, + _ => CapacityStatus::Partial, + } + } + /// Return last delegation amount without popping the delegation + pub fn lowest_delegation_amount(&self) -> Balance { + self.delegations + .last() + .map(|x| x.amount) + .unwrap_or(Balance::zero()) + } + /// Return highest delegation amount + pub fn highest_delegation_amount(&self) -> Balance { + self.delegations + .first() + .map(|x| x.amount) + .unwrap_or(Balance::zero()) + } + } + + #[derive(PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] + /// Capacity status for top or bottom delegations + pub enum CapacityStatus { + /// Reached capacity + Full, + /// Empty aka contains no delegations + Empty, + /// Partially full (nonempty and not full) + Partial, + } + + #[derive(Encode, Decode, RuntimeDebug, TypeInfo)] + /// All candidate info except the top and bottom delegations + pub struct CandidateMetadata { + /// This candidate's self bond amount + pub bond: Balance, + /// Total number of delegations to this candidate + pub delegation_count: u32, + /// Self bond + sum of top delegations + pub total_counted: Balance, + /// The smallest top delegation amount + pub lowest_top_delegation_amount: Balance, + /// The highest bottom delegation amount + pub highest_bottom_delegation_amount: Balance, + /// The smallest bottom delegation amount + pub lowest_bottom_delegation_amount: Balance, + /// Capacity status for top delegations + pub top_capacity: CapacityStatus, + /// Capacity status for bottom delegations + pub bottom_capacity: CapacityStatus, + /// Maximum 1 pending request to decrease candidate self bond at any given time + pub request: Option>, + /// Current status of the collator + pub status: CollatorStatus, } impl< - A: Ord + Clone, - B: AtLeast32BitUnsigned + Ord + Copy + sp_std::ops::AddAssign + sp_std::ops::SubAssign, - > Collator2 + Balance: Copy + + Zero + + PartialOrd + + sp_std::ops::AddAssign + + sp_std::ops::SubAssign + + sp_std::ops::Sub + + sp_std::fmt::Debug, + > CandidateMetadata { - pub fn new(id: A, bond: B) -> Self { - Collator2 { - id, + pub fn new(bond: Balance) -> Self { + CandidateMetadata { bond, - nominators: OrderedSet::new(), - top_nominators: Vec::new(), - bottom_nominators: Vec::new(), + delegation_count: 0u32, total_counted: bond, - total_backing: bond, - state: CollatorStatus::default(), // default active + lowest_top_delegation_amount: Zero::zero(), + highest_bottom_delegation_amount: Zero::zero(), + lowest_bottom_delegation_amount: Zero::zero(), + top_capacity: CapacityStatus::Empty, + bottom_capacity: CapacityStatus::Empty, + request: None, + status: CollatorStatus::Active, } } pub fn is_active(&self) -> bool { - self.state == CollatorStatus::Active + matches!(self.status, CollatorStatus::Active) } pub fn is_leaving(&self) -> bool { - matches!(self.state, CollatorStatus::Leaving(_)) + matches!(self.status, CollatorStatus::Leaving(_)) } - pub fn bond_more(&mut self, more: B) { - self.bond += more; - self.total_counted += more; - self.total_backing += more; - } - // Return None if less >= self.bond => collator must leave instead of bond less - pub fn bond_less(&mut self, less: B) -> Option { - if self.bond > less { - self.bond -= less; - self.total_counted -= less; - self.total_backing -= less; - Some(self.bond) + pub fn schedule_leave( + &mut self, + ) -> Result<(RoundIndex, RoundIndex), DispatchError> { + ensure!(!self.is_leaving(), Error::::CandidateAlreadyLeaving); + let now = >::get().current; + let when = now + T::LeaveCandidatesDelay::get(); + self.status = CollatorStatus::Leaving(when); + Ok((now, when)) + } + pub fn can_leave(&self) -> DispatchResult { + if let CollatorStatus::Leaving(when) = self.status { + ensure!( + >::get().current >= when, + Error::::CandidateCannotLeaveYet + ); + Ok(()) } else { - None + Err(Error::::CandidateNotLeaving.into()) } } - /// Infallible sorted insertion - /// caller must verify !self.nominators.contains(nominator.owner) before call - pub fn add_top_nominator(&mut self, nominator: Bond) { - match self - .top_nominators - .binary_search_by(|x| nominator.amount.cmp(&x.amount)) - { - Ok(i) => self.top_nominators.insert(i, nominator), - Err(i) => self.top_nominators.insert(i, nominator), - } + pub fn go_offline(&mut self) { + self.status = CollatorStatus::Idle; } - /// Infallible sorted insertion - /// caller must verify !self.nominators.contains(nominator.owner) before call - pub fn add_bottom_nominator(&mut self, nominator: Bond) { - match self - .bottom_nominators - .binary_search_by(|x| x.amount.cmp(&nominator.amount)) - { - Ok(i) => self.bottom_nominators.insert(i, nominator), - Err(i) => self.bottom_nominators.insert(i, nominator), + pub fn go_online(&mut self) { + self.status = CollatorStatus::Active; + } + pub fn bond_more(&mut self, who: T::AccountId, more: Balance) -> DispatchResult + where + BalanceOf: From, + { + T::Currency::reserve(&who, more.into())?; + let new_total = >::get().saturating_add(more.into()); + >::put(new_total); + self.bond += more; + self.total_counted += more; + >::deposit_event(Event::CandidateBondedMore( + who.clone(), + more.into(), + self.bond.into(), + )); + Ok(()) + } + /// Schedule executable decrease of collator candidate self bond + /// Returns the round at which the collator can execute the pending request + pub fn schedule_bond_less( + &mut self, + less: Balance, + ) -> Result + where + BalanceOf: Into, + { + // ensure no pending request + ensure!( + self.request.is_none(), + Error::::PendingCandidateRequestAlreadyExists + ); + // ensure bond above min after decrease + ensure!(self.bond > less, Error::::CandidateBondBelowMin); + ensure!( + self.bond - less >= T::MinCandidateStk::get().into(), + Error::::CandidateBondBelowMin + ); + let when_executable = >::get().current + T::CandidateBondLessDelay::get(); + self.request = Some(CandidateBondLessRequest { + amount: less, + when_executable, + }); + Ok(when_executable) + } + /// Execute pending request to decrease the collator self bond + /// Returns the event to be emitted + pub fn execute_bond_less(&mut self, who: T::AccountId) -> DispatchResult + where + BalanceOf: From, + { + let request = self + .request + .ok_or(Error::::PendingCandidateRequestsDNE)?; + ensure!( + request.when_executable <= >::get().current, + Error::::PendingCandidateRequestNotDueYet + ); + T::Currency::unreserve(&who, request.amount.into()); + let new_total_staked = >::get().saturating_sub(request.amount.into()); + >::put(new_total_staked); + // Arithmetic assumptions are self.bond > less && self.bond - less > CollatorMinBond + // (assumptions enforced by `schedule_bond_less`; if storage corrupts, must re-verify) + self.bond -= request.amount; + self.total_counted -= request.amount; + let event = Event::CandidateBondedLess( + who.clone().into(), + request.amount.into(), + self.bond.into(), + ); + // reset s.t. no pending request + self.request = None; + // update candidate pool value because it must change if self bond changes + if self.is_active() { + Pallet::::update_active(who.into(), self.total_counted.into()); } + Pallet::::deposit_event(event); + Ok(()) } - /// Sort top nominators from greatest to least - pub fn sort_top_nominators(&mut self) { - self.top_nominators - .sort_unstable_by(|a, b| b.amount.cmp(&a.amount)); + /// Cancel candidate bond less request + pub fn cancel_bond_less(&mut self, who: T::AccountId) -> DispatchResult + where + BalanceOf: From, + { + let request = self + .request + .ok_or(Error::::PendingCandidateRequestsDNE)?; + let event = Event::CancelledCandidateBondLess( + who.clone().into(), + request.amount.into(), + request.when_executable, + ); + self.request = None; + Pallet::::deposit_event(event); + Ok(()) } - /// Sort bottom nominators from least to greatest - pub fn sort_bottom_nominators(&mut self) { - self.bottom_nominators - .sort_unstable_by(|a, b| a.amount.cmp(&b.amount)); + /// Reset top delegations metadata + pub fn reset_top_data( + &mut self, + top_delegations: &Delegations>, + ) where + BalanceOf: Into, + { + self.lowest_top_delegation_amount = top_delegations.lowest_delegation_amount().into(); + self.top_capacity = top_delegations.top_capacity::(); + self.total_counted = self.bond + top_delegations.total.into(); + } + /// Reset bottom delegations metadata + pub fn reset_bottom_data( + &mut self, + bottom_delegations: &Delegations>, + ) where + BalanceOf: Into, + { + self.lowest_bottom_delegation_amount = + bottom_delegations.lowest_delegation_amount().into(); + self.highest_bottom_delegation_amount = + bottom_delegations.highest_delegation_amount().into(); + self.bottom_capacity = bottom_delegations.bottom_capacity::(); + } + /// Add delegation + /// Returns whether delegator was added and an optional negative total counted remainder + /// for if a bottom delegation was kicked + /// MUST ensure no delegation exists for this candidate in the `DelegatorState` before call + pub fn add_delegation( + &mut self, + candidate: &T::AccountId, + delegation: Bond>, + ) -> Result<(DelegatorAdded, Option), DispatchError> + where + BalanceOf: Into, + { + let mut less_total_staked = None; + let delegator_added = match self.top_capacity { + CapacityStatus::Full => { + // top is full, insert into top iff the lowest_top < amount + if self.lowest_top_delegation_amount < delegation.amount.into() { + // bumps lowest top to the bottom inside this function call + less_total_staked = self.add_top_delegation::(candidate, delegation); + DelegatorAdded::AddedToTop { + new_total: self.total_counted, + } + } else { + // if bottom is full, only insert if greater than lowest bottom (which will + // be bumped out) + if matches!(self.bottom_capacity, CapacityStatus::Full) { + ensure!( + delegation.amount.into() > self.lowest_bottom_delegation_amount, + Error::::CannotDelegateLessThanLowestBottomWhenBottomIsFull + ); + // need to subtract from total staked + less_total_staked = Some(self.lowest_bottom_delegation_amount); + } + // insert into bottom + self.add_bottom_delegation::(false, candidate, delegation); + DelegatorAdded::AddedToBottom + } + } + // top is either empty or partially full + _ => { + self.add_top_delegation::(candidate, delegation); + DelegatorAdded::AddedToTop { + new_total: self.total_counted, + } + } + }; + Ok((delegator_added, less_total_staked)) } - /// Bond a new account as a nominator, and make a first nomination. If successful, - /// the return value indicates whether the nomination is top for the candidate. - pub fn add_nominator( + /// Add delegation to top delegation + /// Returns Option + /// Only call if lowest top delegation is less than delegation.amount || !top_full + pub fn add_top_delegation( &mut self, - acc: A, - amount: B, - ) -> Result, DispatchError> { - ensure!( - self.nominators.insert(acc.clone()), - Error::::NominatorExists - ); - self.total_backing += amount; - if (self.top_nominators.len() as u32) < T::MaxNominatorsPerCollator::get() { - self.add_top_nominator(Bond { owner: acc, amount }); - self.total_counted += amount; - Ok(NominatorAdded::AddedToTop { - new_total: self.total_counted, - }) - } else { - // >pop requires push to reset in case isn't pushed to bottom - let last_nomination_in_top = self - .top_nominators + candidate: &T::AccountId, + delegation: Bond>, + ) -> Option + where + BalanceOf: Into, + { + let mut less_total_staked = None; + let mut top_delegations = >::get(candidate) + .expect("CandidateInfo existence => TopDelegations existence"); + let max_top_delegations_per_candidate = T::MaxTopDelegationsPerCandidate::get(); + if top_delegations.delegations.len() as u32 == max_top_delegations_per_candidate { + // pop lowest top delegation + let new_bottom_delegation = top_delegations.delegations.pop().expect(""); + top_delegations.total = top_delegations + .total + .saturating_sub(new_bottom_delegation.amount); + if matches!(self.bottom_capacity, CapacityStatus::Full) { + less_total_staked = Some(self.lowest_bottom_delegation_amount); + } + self.add_bottom_delegation::(true, candidate, new_bottom_delegation); + } + // insert into top + top_delegations.insert_sorted_greatest_to_least(delegation); + // update candidate info + self.reset_top_data::(&top_delegations); + if less_total_staked.is_none() { + // only increment delegation count if we are not kicking a bottom delegation + self.delegation_count += 1u32; + } + >::insert(&candidate, top_delegations); + less_total_staked + } + /// Add delegation to bottom delegations + /// Check before call that if capacity is full, inserted delegation is higher than lowest + /// bottom delegation (and if so, need to adjust the total storage item) + /// CALLER MUST ensure(lowest_bottom_to_be_kicked.amount < delegation.amount) + pub fn add_bottom_delegation( + &mut self, + bumped_from_top: bool, + candidate: &T::AccountId, + delegation: Bond>, + ) where + BalanceOf: Into, + { + let mut bottom_delegations = >::get(candidate) + .expect("CandidateInfo existence => BottomDelegations existence"); + // if bottom is full, kick the lowest bottom (which is expected to be lower than input + // as per check) + let increase_delegation_count = if bottom_delegations.delegations.len() as u32 + == T::MaxBottomDelegationsPerCandidate::get() + { + let lowest_bottom_to_be_kicked = bottom_delegations + .delegations .pop() - .expect("self.top_nominators.len() >= T::Max exists >= 1 element in top"); - if amount > last_nomination_in_top.amount { - // update total_counted with positive difference - self.total_counted += amount - last_nomination_in_top.amount; - // last nomination already popped from top_nominators - // insert new nominator into top_nominators - self.add_top_nominator(Bond { owner: acc, amount }); - self.add_bottom_nominator(last_nomination_in_top); - Ok(NominatorAdded::AddedToTop { - new_total: self.total_counted, - }) + .expect("if at full capacity (>0), then >0 bottom delegations exist; qed"); + // EXPECT lowest_bottom_to_be_kicked.amount < delegation.amount enforced by caller + // if lowest_bottom_to_be_kicked.amount == delegation.amount, we will still kick + // the lowest bottom to enforce first come first served + bottom_delegations.total = bottom_delegations + .total + .saturating_sub(lowest_bottom_to_be_kicked.amount); + // update delegator state + // unreserve kicked bottom + T::Currency::unreserve( + &lowest_bottom_to_be_kicked.owner, + lowest_bottom_to_be_kicked.amount, + ); + // total staked is updated via propagation of lowest bottom delegation amount prior + // to call + let mut delegator_state = + >::get(&lowest_bottom_to_be_kicked.owner) + .expect("Delegation existence => DelegatorState existence"); + let leaving = delegator_state.delegations.0.len() == 1usize; + delegator_state.rm_delegation(candidate); + Pallet::::deposit_event(Event::DelegationKicked( + lowest_bottom_to_be_kicked.owner.clone(), + candidate.clone(), + lowest_bottom_to_be_kicked.amount, + )); + if leaving { + >::remove(&lowest_bottom_to_be_kicked.owner); + Pallet::::deposit_event(Event::DelegatorLeft( + lowest_bottom_to_be_kicked.owner, + lowest_bottom_to_be_kicked.amount, + )); } else { - // >required push to previously popped last nomination into top_nominators - self.top_nominators.push(last_nomination_in_top); - self.add_bottom_nominator(Bond { owner: acc, amount }); - Ok(NominatorAdded::AddedToBottom) + >::insert( + &lowest_bottom_to_be_kicked.owner, + delegator_state, + ); } + false + } else { + !bumped_from_top + }; + // only increase delegation count if new bottom delegation (1) doesn't come from top && + // (2) doesn't pop the lowest delegation from the bottom + if increase_delegation_count { + self.delegation_count += 1u32; + } + bottom_delegations.insert_sorted_greatest_to_least(delegation); + self.reset_bottom_data::(&bottom_delegations); + >::insert(candidate, bottom_delegations); + } + /// Remove delegation + /// Removes from top if amount is above lowest top or top is not full + /// Return Ok(if_total_counted_changed) + pub fn rm_delegation_if_exists( + &mut self, + candidate: &T::AccountId, + delegator: T::AccountId, + amount: Balance, + ) -> Result + where + BalanceOf: Into + From, + { + let amount_geq_lowest_top = amount >= self.lowest_top_delegation_amount; + let top_is_not_full = !matches!(self.top_capacity, CapacityStatus::Full); + let lowest_top_eq_highest_bottom = + self.lowest_top_delegation_amount == self.highest_bottom_delegation_amount; + let delegation_dne_err: DispatchError = Error::::DelegationDNE.into(); + if top_is_not_full || (amount_geq_lowest_top && !lowest_top_eq_highest_bottom) { + self.rm_top_delegation::(candidate, delegator) + } else if amount_geq_lowest_top && lowest_top_eq_highest_bottom { + let result = self.rm_top_delegation::(candidate, delegator.clone()); + if result == Err(delegation_dne_err) { + // worst case removal + self.rm_bottom_delegation::(candidate, delegator) + } else { + result + } + } else { + self.rm_bottom_delegation::(candidate, delegator) } } - /// Return Ok((if_total_counted_changed, nominator's stake)) - pub fn rm_nominator( + /// Remove top delegation, bumps top bottom delegation if exists + pub fn rm_top_delegation( &mut self, - nominator: A, - ) -> Result<(bool, B), DispatchError> { - ensure!( - self.nominators.remove(&nominator), - Error::::NominatorDNEInNominatorSet - ); - let mut nominator_stake: Option = None; - self.top_nominators = self - .top_nominators + candidate: &T::AccountId, + delegator: T::AccountId, + ) -> Result + where + BalanceOf: Into, + { + let old_total_counted = self.total_counted; + // remove top delegation + let mut top_delegations = >::get(candidate) + .expect("CandidateInfo exists => TopDelegations exists"); + let mut actual_amount_option: Option> = None; + top_delegations.delegations = top_delegations + .delegations .clone() .into_iter() - .filter_map(|nom| { - if nom.owner != nominator { - Some(nom) + .filter_map(|d| { + if d.owner != delegator { + Some(d) } else { - nominator_stake = Some(nom.amount); + actual_amount_option = Some(d.amount); None } }) .collect(); - // item removed from the top => highest bottom is popped from bottom and pushed to top - if let Some(s) = nominator_stake { - // last element has largest amount as per ordering - if let Some(last) = self.bottom_nominators.pop() { - self.total_counted -= s - last.amount; - self.add_top_nominator(last); - } else { - // no item in bottom nominators so no item from bottom to pop and push up - self.total_counted -= s; - } - self.total_backing -= s; - return Ok((true, s)); + let actual_amount = actual_amount_option.ok_or(Error::::DelegationDNE)?; + top_delegations.total -= actual_amount; + // if bottom nonempty => bump top bottom to top + if !matches!(self.bottom_capacity, CapacityStatus::Empty) { + let mut bottom_delegations = >::get(candidate) + .expect("bottom is nonempty as just checked"); + // expect already stored greatest to least by bond amount + let highest_bottom_delegation = bottom_delegations.delegations.remove(0); + bottom_delegations.total = bottom_delegations + .total + .saturating_sub(highest_bottom_delegation.amount); + self.reset_bottom_data::(&bottom_delegations); + >::insert(candidate, bottom_delegations); + // insert highest bottom into top delegations + top_delegations.insert_sorted_greatest_to_least(highest_bottom_delegation); } - // else (no item removed from the top) - self.bottom_nominators = self - .bottom_nominators + // update candidate info + self.reset_top_data::(&top_delegations); + self.delegation_count -= 1u32; + >::insert(candidate, top_delegations); + // return whether total counted changed + Ok(old_total_counted == self.total_counted) + } + /// Remove bottom delegation + /// Returns if_total_counted_changed: bool + pub fn rm_bottom_delegation( + &mut self, + candidate: &T::AccountId, + delegator: T::AccountId, + ) -> Result + where + BalanceOf: Into, + { + // remove bottom delegation + let mut bottom_delegations = >::get(candidate) + .expect("CandidateInfo exists => BottomDelegations exists"); + let mut actual_amount_option: Option> = None; + bottom_delegations.delegations = bottom_delegations + .delegations .clone() .into_iter() - .filter_map(|nom| { - if nom.owner != nominator { - Some(nom) + .filter_map(|d| { + if d.owner != delegator { + Some(d) } else { - nominator_stake = Some(nom.amount); + actual_amount_option = Some(d.amount); None } }) .collect(); - // if err, no item with account exists in top || bottom - let stake = nominator_stake.ok_or(Error::::NominatorDNEinTopNorBottom)?; - self.total_backing -= stake; - Ok((false, stake)) - } - /// Return true if in_top after call - /// Caller must verify before call that account is a nominator - pub fn inc_nominator(&mut self, nominator: A, more: B) -> bool { - let mut in_top = false; - for x in &mut self.top_nominators { - if x.owner == nominator { - x.amount += more; - self.total_counted += more; - self.total_backing += more; - in_top = true; - break; + let actual_amount = actual_amount_option.ok_or(Error::::DelegationDNE)?; + bottom_delegations.total = bottom_delegations.total.saturating_sub(actual_amount); + // update candidate info + self.reset_bottom_data::(&bottom_delegations); + self.delegation_count = self.delegation_count.saturating_sub(1u32); + >::insert(candidate, bottom_delegations); + Ok(false) + } + /// Increase delegation amount + pub fn increase_delegation( + &mut self, + candidate: &T::AccountId, + delegator: T::AccountId, + bond: BalanceOf, + more: BalanceOf, + ) -> Result + where + BalanceOf: Into, + { + let lowest_top_eq_highest_bottom = + self.lowest_top_delegation_amount == self.highest_bottom_delegation_amount; + let bond_geq_lowest_top = bond.into() >= self.lowest_top_delegation_amount; + let delegation_dne_err: DispatchError = Error::::DelegationDNE.into(); + if bond_geq_lowest_top && !lowest_top_eq_highest_bottom { + // definitely in top + self.increase_top_delegation::(candidate, delegator.clone(), more) + } else if bond_geq_lowest_top && lowest_top_eq_highest_bottom { + // update top but if error then update bottom (because could be in bottom because + // lowest_top_eq_highest_bottom) + let result = + self.increase_top_delegation::(candidate, delegator.clone(), more); + if result == Err(delegation_dne_err) { + self.increase_bottom_delegation::(candidate, delegator, bond, more) + } else { + result } + } else { + self.increase_bottom_delegation::(candidate, delegator, bond, more) } - // if nominator was increased in top nominators - if in_top { - self.sort_top_nominators(); - return true; - } - // else nominator to increase must exist in bottom - // >pop requires push later on to reset in case it isn't used - let lowest_top = self - .top_nominators - .pop() - .expect("any bottom nominators => exists T::Max top nominators"); - let mut move_2_top = false; - for x in &mut self.bottom_nominators { - if x.owner == nominator { - x.amount += more; - self.total_backing += more; - move_2_top = x.amount > lowest_top.amount; - break; + } + /// Increase top delegation + pub fn increase_top_delegation( + &mut self, + candidate: &T::AccountId, + delegator: T::AccountId, + more: BalanceOf, + ) -> Result + where + BalanceOf: Into, + { + let mut top_delegations = >::get(candidate) + .expect("CandidateInfo exists => TopDelegations exists"); + let mut in_top = false; + top_delegations.delegations = top_delegations + .delegations + .clone() + .into_iter() + .map(|d| { + if d.owner != delegator { + d + } else { + in_top = true; + let new_amount = d.amount.saturating_add(more); + Bond { + owner: d.owner, + amount: new_amount, + } + } + }) + .collect(); + ensure!(in_top, Error::::DelegationDNE); + top_delegations.sort_greatest_to_least(); + self.reset_top_data::(&top_delegations); + >::insert(candidate, top_delegations); + Ok(true) + } + /// Increase bottom delegation + pub fn increase_bottom_delegation( + &mut self, + candidate: &T::AccountId, + delegator: T::AccountId, + bond: BalanceOf, + more: BalanceOf, + ) -> Result + where + BalanceOf: Into, + { + let mut bottom_delegations = + >::get(candidate).ok_or(Error::::CandidateDNE)?; + let mut delegation_option: Option>> = None; + let in_top_after = + if (bond.saturating_add(more)).into() > self.lowest_top_delegation_amount { + // bump it from bottom + bottom_delegations.delegations = bottom_delegations + .delegations + .clone() + .into_iter() + .filter_map(|d| { + if d.owner != delegator { + Some(d) + } else { + delegation_option = Some(Bond { + owner: d.owner, + amount: d.amount.saturating_add(more), + }); + None + } + }) + .collect(); + let delegation = delegation_option.ok_or(Error::::DelegationDNE)?; + bottom_delegations.total = bottom_delegations.total.saturating_sub(bond); + // add it to top + let mut top_delegations = >::get(candidate) + .expect("CandidateInfo existence => TopDelegations existence"); + // if top is full, pop lowest top + if matches!(top_delegations.top_capacity::(), CapacityStatus::Full) { + // pop lowest top delegation + let new_bottom_delegation = top_delegations + .delegations + .pop() + .expect("Top capacity full => Exists at least 1 top delegation"); + top_delegations.total = top_delegations + .total + .saturating_sub(new_bottom_delegation.amount); + bottom_delegations.insert_sorted_greatest_to_least(new_bottom_delegation); + } + // insert into top + top_delegations.insert_sorted_greatest_to_least(delegation); + self.reset_top_data::(&top_delegations); + >::insert(candidate, top_delegations); + true + } else { + let mut in_bottom = false; + // just increase the delegation + bottom_delegations.delegations = bottom_delegations + .delegations + .clone() + .into_iter() + .map(|d| { + if d.owner != delegator { + d + } else { + in_bottom = true; + Bond { + owner: d.owner, + amount: d.amount.saturating_add(more), + } + } + }) + .collect(); + ensure!(in_bottom, Error::::DelegationDNE); + bottom_delegations.sort_greatest_to_least(); + false + }; + self.reset_bottom_data::(&bottom_delegations); + >::insert(candidate, bottom_delegations); + Ok(in_top_after) + } + /// Decrease delegation + pub fn decrease_delegation( + &mut self, + candidate: &T::AccountId, + delegator: T::AccountId, + bond: Balance, + less: BalanceOf, + ) -> Result + where + BalanceOf: Into + From, + { + let lowest_top_eq_highest_bottom = + self.lowest_top_delegation_amount == self.highest_bottom_delegation_amount; + let bond_geq_lowest_top = bond >= self.lowest_top_delegation_amount; + let delegation_dne_err: DispatchError = Error::::DelegationDNE.into(); + if bond_geq_lowest_top && !lowest_top_eq_highest_bottom { + // definitely in top + self.decrease_top_delegation::(candidate, delegator.clone(), bond.into(), less) + } else if bond_geq_lowest_top && lowest_top_eq_highest_bottom { + // update top but if error then update bottom (because could be in bottom because + // lowest_top_eq_highest_bottom) + let result = self.decrease_top_delegation::( + candidate, + delegator.clone(), + bond.into(), + less, + ); + if result == Err(delegation_dne_err) { + self.decrease_bottom_delegation::(candidate, delegator, less) + } else { + result } - } - if move_2_top { - self.sort_bottom_nominators(); - let highest_bottom = self.bottom_nominators.pop().expect("updated => exists"); - self.total_counted += highest_bottom.amount - lowest_top.amount; - self.add_top_nominator(highest_bottom); - self.add_bottom_nominator(lowest_top); - true } else { - // >required push to reset top_nominators from earlier pop - self.top_nominators.push(lowest_top); - self.sort_bottom_nominators(); - false + self.decrease_bottom_delegation::(candidate, delegator, less) } } - /// Return true if in_top after call - pub fn dec_nominator(&mut self, nominator: A, less: B) -> bool { - let mut in_top = false; - let mut new_lowest_top: Option> = None; - for x in &mut self.top_nominators { - if x.owner == nominator { - x.amount -= less; - // if there is at least 1 nominator in bottom nominators, compare it to check - // if it should be swapped with lowest top nomination and put in top - // >pop requires push later on to reset in case it isn't used - if let Some(highest_bottom) = self.bottom_nominators.pop() { - if highest_bottom.amount > x.amount { - new_lowest_top = Some(highest_bottom); - } else { - // >required push to reset self.bottom_nominators - self.bottom_nominators.push(highest_bottom); + /// Decrease top delegation + pub fn decrease_top_delegation( + &mut self, + candidate: &T::AccountId, + delegator: T::AccountId, + bond: BalanceOf, + less: BalanceOf, + ) -> Result + where + BalanceOf: Into, + { + // The delegation after the `decrease-delegation` will be strictly less than the + // highest bottom delegation + let bond_after_less_than_highest_bottom = + bond.saturating_sub(less).into() < self.highest_bottom_delegation_amount; + // The top delegations is full and the bottom delegations has at least one delegation + let full_top_and_nonempty_bottom = matches!(self.top_capacity, CapacityStatus::Full) + && !matches!(self.bottom_capacity, CapacityStatus::Empty); + let mut top_delegations = + >::get(candidate).ok_or(Error::::CandidateDNE)?; + let in_top_after = + if bond_after_less_than_highest_bottom && full_top_and_nonempty_bottom { + let mut delegation_option: Option>> = None; + // take delegation from top + top_delegations.delegations = top_delegations + .delegations + .clone() + .into_iter() + .filter_map(|d| { + if d.owner != delegator { + Some(d) + } else { + top_delegations.total = + top_delegations.total.saturating_sub(d.amount); + delegation_option = Some(Bond { + owner: d.owner, + amount: d.amount.saturating_sub(less), + }); + None + } + }) + .collect(); + let delegation = delegation_option.ok_or(Error::::DelegationDNE)?; + // pop highest bottom by reverse and popping + let mut bottom_delegations = >::get(candidate) + .expect("CandidateInfo existence => BottomDelegations existence"); + let highest_bottom_delegation = bottom_delegations.delegations.remove(0); + bottom_delegations.total = bottom_delegations + .total + .saturating_sub(highest_bottom_delegation.amount); + // insert highest bottom into top + top_delegations.insert_sorted_greatest_to_least(highest_bottom_delegation); + // insert previous top into bottom + bottom_delegations.insert_sorted_greatest_to_least(delegation); + self.reset_bottom_data::(&bottom_delegations); + >::insert(candidate, bottom_delegations); + false + } else { + // keep it in the top + let mut is_in_top = false; + top_delegations.delegations = top_delegations + .delegations + .clone() + .into_iter() + .map(|d| { + if d.owner != delegator { + d + } else { + is_in_top = true; + Bond { + owner: d.owner, + amount: d.amount.saturating_sub(less), + } + } + }) + .collect(); + ensure!(is_in_top, Error::::DelegationDNE); + top_delegations.total = top_delegations.total.saturating_sub(less); + top_delegations.sort_greatest_to_least(); + true + }; + self.reset_top_data::(&top_delegations); + >::insert(candidate, top_delegations); + Ok(in_top_after) + } + /// Decrease bottom delegation + pub fn decrease_bottom_delegation( + &mut self, + candidate: &T::AccountId, + delegator: T::AccountId, + less: BalanceOf, + ) -> Result + where + BalanceOf: Into, + { + let mut bottom_delegations = >::get(candidate) + .expect("CandidateInfo exists => BottomDelegations exists"); + let mut in_bottom = false; + bottom_delegations.delegations = bottom_delegations + .delegations + .clone() + .into_iter() + .map(|d| { + if d.owner != delegator { + d + } else { + in_bottom = true; + Bond { + owner: d.owner, + amount: d.amount.saturating_sub(less), } } - in_top = true; - break; + }) + .collect(); + ensure!(in_bottom, Error::::DelegationDNE); + bottom_delegations.sort_greatest_to_least(); + self.reset_bottom_data::(&bottom_delegations); + >::insert(candidate, bottom_delegations); + Ok(false) + } + } + + // Temporary manual implementation for migration testing purposes + impl PartialEq for CollatorCandidate { + fn eq(&self, other: &Self) -> bool { + let must_be_true = self.id == other.id + && self.bond == other.bond + && self.total_counted == other.total_counted + && self.total_backing == other.total_backing + && self.request == other.request + && self.state == other.state; + if !must_be_true { + return false; + } + for (x, y) in self.delegators.0.iter().zip(other.delegators.0.iter()) { + if x != y { + return false; } } - if in_top { - self.sort_top_nominators(); - if let Some(highest_bottom) = new_lowest_top { - // pop last in top to swap it with top bottom - let lowest_top = self - .top_nominators - .pop() - .expect("must have >1 item to update, assign in_top = true"); - self.total_counted -= lowest_top.amount + less; - self.total_counted += highest_bottom.amount; - self.total_backing -= less; - self.add_top_nominator(highest_bottom); - self.add_bottom_nominator(lowest_top); + for ( + Bond { + owner: o1, + amount: a1, + }, + Bond { + owner: o2, + amount: a2, + }, + ) in self + .top_delegations + .iter() + .zip(other.top_delegations.iter()) + { + if o1 != o2 || a1 != a2 { return false; - } else { - // no existing bottom nominators so update both counters the same magnitude - self.total_counted -= less; - self.total_backing -= less; - return true; } } - for x in &mut self.bottom_nominators { - if x.owner == nominator { - x.amount -= less; - self.total_backing -= less; - break; + for ( + Bond { + owner: o1, + amount: a1, + }, + Bond { + owner: o2, + amount: a2, + }, + ) in self + .bottom_delegations + .iter() + .zip(other.bottom_delegations.iter()) + { + if o1 != o2 || a1 != a2 { + return false; } } - self.sort_bottom_nominators(); - false - } - pub fn go_offline(&mut self) { - self.state = CollatorStatus::Idle; - } - pub fn go_online(&mut self) { - self.state = CollatorStatus::Active; + true } - pub fn leave(&mut self, when: RoundIndex) { - self.state = CollatorStatus::Leaving(when); + } + + /// Convey relevant information describing if a delegator was added to the top or bottom + /// Delegations added to the top yield a new total + #[derive(Clone, Copy, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] + pub enum DelegatorAdded { + AddedToTop { new_total: B }, + AddedToBottom, + } + + impl< + A: Ord + Clone + sp_std::fmt::Debug, + B: AtLeast32BitUnsigned + + Ord + + Copy + + sp_std::ops::AddAssign + + sp_std::ops::SubAssign + + sp_std::fmt::Debug, + > CollatorCandidate + { + pub fn is_active(&self) -> bool { + self.state == CollatorStatus::Active } } - impl From> for CollatorSnapshot { - fn from(other: Collator2) -> CollatorSnapshot { + impl From> for CollatorSnapshot { + fn from(other: CollatorCandidate) -> CollatorSnapshot { CollatorSnapshot { bond: other.bond, - nominators: other.top_nominators, + delegations: other.top_delegations, total: other.total_counted, } } } #[derive(Clone, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] - pub enum NominatorStatus { + pub enum DelegatorStatus { /// Active with no scheduled exit Active, - /// Schedule exit to revoke all ongoing nominations + /// Schedule exit to revoke all ongoing delegations Leaving(RoundIndex), } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo)] - /// Nominator state - pub struct Nominator2 { - /// All current nominations - pub nominations: OrderedSet>, - /// Nominations scheduled to be revoked - pub revocations: OrderedSet, - /// Total balance locked for this nominator + /// Delegator state + pub struct Delegator { + /// Delegator account + pub id: AccountId, + /// All current delegations + pub delegations: OrderedSet>, + /// Total balance locked for this delegator pub total: Balance, - /// Total number of revocations scheduled to be executed - pub scheduled_revocations_count: u32, - /// Total amount to be unbonded once revocations are executed - pub scheduled_revocations_total: Balance, - /// Status for this nominator - pub status: NominatorStatus, + /// Requests to change delegations, relevant iff active + pub requests: PendingDelegationRequests, + /// Status for this delegator + pub status: DelegatorStatus, + } + + // Temporary manual implementation for migration testing purposes + impl PartialEq for Delegator { + fn eq(&self, other: &Self) -> bool { + let must_be_true = self.id == other.id + && self.total == other.total + && self.requests == other.requests + && self.status == other.status; + if !must_be_true { + return false; + } + for ( + Bond { + owner: o1, + amount: a1, + }, + Bond { + owner: o2, + amount: a2, + }, + ) in self.delegations.0.iter().zip(other.delegations.0.iter()) + { + if o1 != o2 || a1 != a2 { + return false; + } + } + true + } } impl< @@ -490,52 +1277,87 @@ pub mod pallet { + sp_std::ops::AddAssign + sp_std::ops::Add + sp_std::ops::SubAssign - + PartialOrd - + Zero, - > Nominator2 + + sp_std::ops::Sub + + Ord + + Zero + + Default, + > Delegator { - pub fn new(collator: AccountId, amount: Balance) -> Self { - Nominator2 { - nominations: OrderedSet::from(vec![Bond { + pub fn new(id: AccountId, collator: AccountId, amount: Balance) -> Self { + Delegator { + id, + delegations: OrderedSet::from(vec![Bond { owner: collator, amount, }]), - revocations: OrderedSet::new(), total: amount, - scheduled_revocations_count: 0u32, - scheduled_revocations_total: Zero::zero(), - status: NominatorStatus::Active, + requests: PendingDelegationRequests::new(), + status: DelegatorStatus::Active, } } + pub fn requests(&self) -> BTreeMap> { + self.requests.requests.clone() + } pub fn is_active(&self) -> bool { - matches!(self.status, NominatorStatus::Active) + matches!(self.status, DelegatorStatus::Active) } pub fn is_leaving(&self) -> bool { - matches!(self.status, NominatorStatus::Leaving(_)) + matches!(self.status, DelegatorStatus::Leaving(_)) + } + /// Can only leave if the current round is less than or equal to scheduled execution round + /// - returns None if not in leaving state + pub fn can_execute_leave( + &self, + delegation_weight_hint: u32, + ) -> DispatchResult { + ensure!( + delegation_weight_hint >= (self.delegations.0.len() as u32), + Error::::TooLowDelegationCountToLeaveDelegators + ); + if let DelegatorStatus::Leaving(when) = self.status { + ensure!( + >::get().current >= when, + Error::::DelegatorCannotLeaveYet + ); + Ok(()) + } else { + Err(Error::::DelegatorNotLeaving.into()) + } } - /// Set nominator status to exit - pub fn leave(&mut self, when: RoundIndex) { - self.status = NominatorStatus::Leaving(when) + /// Set status to leaving + pub(crate) fn set_leaving(&mut self, when: RoundIndex) { + self.status = DelegatorStatus::Leaving(when); } - pub fn add_nomination(&mut self, bond: Bond) -> bool { + /// Schedule status to exit + pub fn schedule_leave(&mut self) -> (RoundIndex, RoundIndex) { + let now = >::get().current; + let when = now + T::LeaveDelegatorsDelay::get(); + self.set_leaving(when); + (now, when) + } + /// Set delegator status to active + pub fn cancel_leave(&mut self) { + self.status = DelegatorStatus::Active + } + pub fn add_delegation(&mut self, bond: Bond) -> bool { let amt = bond.amount; - if self.nominations.insert(bond) { + if self.delegations.insert(bond) { self.total += amt; true } else { false } } - // Return Some(remaining balance), must be more than MinNominatorStk - // Return None if nomination not found - pub fn rm_nomination(&mut self, collator: AccountId) -> Option { + // Return Some(remaining balance), must be more than MinDelegatorStk + // Return None if delegation not found + pub fn rm_delegation(&mut self, collator: &AccountId) -> Option { let mut amt: Option = None; - let nominations = self - .nominations + let delegations = self + .delegations .0 .iter() .filter_map(|x| { - if x.owner == collator { + if &x.owner == collator { amt = Some(x.amount); None } else { @@ -544,48 +1366,424 @@ pub mod pallet { }) .collect(); if let Some(balance) = amt { - self.nominations = OrderedSet::from(nominations); + self.delegations = OrderedSet::from(delegations); self.total -= balance; Some(self.total) } else { None } } - // Return false if nomination not found - pub fn inc_nomination(&mut self, collator: AccountId, more: Balance) -> bool { - for x in &mut self.nominations.0 { - if x.owner == collator { - x.amount += more; - self.total += more; - return true; + pub fn increase_delegation( + &mut self, + candidate: AccountId, + amount: Balance, + ) -> DispatchResult + where + BalanceOf: From, + T::AccountId: From, + Delegator>: From>, + { + let delegator_id: T::AccountId = self.id.clone().into(); + let candidate_id: T::AccountId = candidate.clone().into(); + let balance_amt: BalanceOf = amount.into(); + // increase delegation + for x in &mut self.delegations.0 { + if x.owner == candidate { + let before_amount: BalanceOf = x.amount.into(); + x.amount += amount; + self.total += amount; + // update collator state delegation + let mut collator_state = + >::get(&candidate_id).ok_or(Error::::CandidateDNE)?; + T::Currency::reserve(&self.id.clone().into(), balance_amt)?; + let before = collator_state.total_counted; + let in_top = collator_state.increase_delegation::( + &candidate_id, + delegator_id.clone(), + before_amount, + balance_amt, + )?; + let after = collator_state.total_counted; + if collator_state.is_active() && (before != after) { + Pallet::::update_active(candidate_id.clone(), after); + } + >::insert(&candidate_id, collator_state); + let new_total_staked = >::get().saturating_add(balance_amt); + >::put(new_total_staked); + let nom_st: Delegator> = self.clone().into(); + >::insert(&delegator_id, nom_st); + Pallet::::deposit_event(Event::DelegationIncreased( + delegator_id, + candidate_id, + balance_amt, + in_top, + )); + return Ok(()); } } - false + Err(Error::::DelegationDNE.into()) } - // Return Some(Some(balance)) if successful - // Return None if nomination not found - // Return Some(None) if less >= nomination_total - pub fn dec_nomination( + /// Schedule decrease delegation + pub fn schedule_decrease_delegation( &mut self, collator: AccountId, less: Balance, - ) -> Option> { - for x in &mut self.nominations.0 { - if x.owner == collator { - if x.amount > less { - x.amount -= less; - self.total -= less; - return Some(Some(x.amount)); + ) -> Result + where + BalanceOf: Into + From, + { + // get delegation amount + let Bond { amount, .. } = self + .delegations + .0 + .iter() + .find(|b| b.owner == collator) + .ok_or(Error::::DelegationDNE)?; + ensure!(*amount > less, Error::::DelegatorBondBelowMin); + let expected_amt: BalanceOf = (*amount - less).into(); + ensure!( + expected_amt >= T::MinDelegation::get(), + Error::::DelegationBelowMin + ); + // Net Total is total after pending orders are executed + let net_total = self.total - self.requests.less_total; + // Net Total is always >= MinDelegatorStk + let max_subtracted_amount = net_total - T::MinDelegatorStk::get().into(); + ensure!( + less <= max_subtracted_amount, + Error::::DelegatorBondBelowMin + ); + let when = >::get().current + T::DelegationBondLessDelay::get(); + self.requests.bond_less::(collator, less, when)?; + Ok(when) + } + /// Temporary function to migrate revocations + pub fn hotfix_set_revoke(&mut self, collator: AccountId, when: RoundIndex) { + // get delegation amount + let maybe_bond = self.delegations.0.iter().find(|b| b.owner == collator); + if let Some(Bond { amount, .. }) = maybe_bond { + // add revocation to pending requests + if let Err(e) = self.requests.revoke::(collator, *amount, when) { + log::warn!("Migrate revocation request failed with error: {:?}", e); + } + } else { + log::warn!("Migrate revocation request failed because delegation DNE"); + } + } + /// Schedule revocation for the given collator + pub fn schedule_revoke( + &mut self, + collator: AccountId, + ) -> Result<(RoundIndex, RoundIndex), DispatchError> + where + BalanceOf: Into, + { + // get delegation amount + let Bond { amount, .. } = self + .delegations + .0 + .iter() + .find(|b| b.owner == collator) + .ok_or(Error::::DelegationDNE)?; + let now = >::get().current; + let when = now + T::RevokeDelegationDelay::get(); + // add revocation to pending requests + self.requests.revoke::(collator, *amount, when)?; + Ok((now, when)) + } + /// Execute pending delegation change request + pub fn execute_pending_request( + &mut self, + candidate: AccountId, + ) -> DispatchResult + where + BalanceOf: From + Into, + T::AccountId: From, + Delegator>: From>, + { + let now = >::get().current; + let DelegationRequest { + amount, + action, + when_executable, + .. + } = self + .requests + .requests + .remove(&candidate) + .ok_or(Error::::PendingDelegationRequestDNE)?; + ensure!( + when_executable <= now, + Error::::PendingDelegationRequestNotDueYet + ); + let (balance_amt, candidate_id, delegator_id): ( + BalanceOf, + T::AccountId, + T::AccountId, + ) = ( + amount.into(), + candidate.clone().into(), + self.id.clone().into(), + ); + match action { + DelegationChange::Revoke => { + // revoking last delegation => leaving set of delegators + let leaving = if self.delegations.0.len() == 1usize { + true + } else { + ensure!( + self.total - T::MinDelegatorStk::get().into() >= amount, + Error::::DelegatorBondBelowMin + ); + false + }; + // remove from pending requests + self.requests.less_total -= amount; + self.requests.revocations_count -= 1u32; + // remove delegation from delegator state + self.rm_delegation(&candidate); + // remove delegation from collator state delegations + Pallet::::delegator_leaves_candidate( + candidate_id.clone(), + delegator_id.clone(), + balance_amt, + )?; + Pallet::::deposit_event(Event::DelegationRevoked( + delegator_id.clone(), + candidate_id, + balance_amt, + )); + if leaving { + >::remove(&delegator_id); + Pallet::::deposit_event(Event::DelegatorLeft( + delegator_id, + balance_amt, + )); } else { - // must rm entire nomination if x.amount <= less - return Some(None); + let nom_st: Delegator> = self.clone().into(); + >::insert(&delegator_id, nom_st); } + Ok(()) } + DelegationChange::Decrease => { + // remove from pending requests + self.requests.less_total -= amount; + // decrease delegation + for x in &mut self.delegations.0 { + if x.owner == candidate { + if x.amount > amount { + let amount_before: BalanceOf = x.amount.into(); + x.amount -= amount; + self.total -= amount; + let new_total: BalanceOf = self.total.into(); + ensure!( + new_total >= T::MinDelegation::get(), + Error::::DelegationBelowMin + ); + ensure!( + new_total >= T::MinDelegatorStk::get(), + Error::::DelegatorBondBelowMin + ); + let mut collator = >::get(&candidate_id) + .ok_or(Error::::CandidateDNE)?; + T::Currency::unreserve(&delegator_id, balance_amt); + let before = collator.total_counted; + // need to go into decrease_delegation + let in_top = collator.decrease_delegation::( + &candidate_id, + delegator_id.clone(), + amount_before, + balance_amt, + )?; + let after = collator.total_counted; + if collator.is_active() && (before != after) { + Pallet::::update_active(candidate_id.clone(), after); + } + >::insert(&candidate_id, collator); + let new_total_staked = + >::get().saturating_sub(balance_amt); + >::put(new_total_staked); + let nom_st: Delegator> = + self.clone().into(); + >::insert(&delegator_id, nom_st); + Pallet::::deposit_event(Event::DelegationDecreased( + delegator_id, + candidate_id, + balance_amt, + in_top, + )); + return Ok(()); + } else { + // must rm entire delegation if x.amount <= less or cancel request + return Err(Error::::DelegationBelowMin.into()); + } + } + } + Err(Error::::DelegationDNE.into()) + } + } + } + /// Cancel pending delegation change request + pub fn cancel_pending_request( + &mut self, + candidate: AccountId, + ) -> Result, DispatchError> { + let order = self + .requests + .requests + .remove(&candidate) + .ok_or(Error::::PendingDelegationRequestDNE)?; + match order.action { + DelegationChange::Revoke => { + self.requests.revocations_count -= 1u32; + self.requests.less_total -= order.amount; + } + DelegationChange::Decrease => { + self.requests.less_total -= order.amount; + } + } + Ok(order) + } + } + + #[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] + /// Changes requested by the delegator + /// - limit of 1 ongoing change per delegation + pub enum DelegationChange { + Revoke, + Decrease, + } + + #[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] + pub struct DelegationRequest { + pub collator: AccountId, + pub amount: Balance, + pub when_executable: RoundIndex, + pub action: DelegationChange, + } + + #[derive(Clone, Encode, PartialEq, Decode, RuntimeDebug, TypeInfo)] + /// Pending requests to mutate delegations for each delegator + pub struct PendingDelegationRequests { + /// Number of pending revocations (necessary for determining whether revoke is exit) + pub revocations_count: u32, + /// Map from collator -> Request (enforces at most 1 pending request per delegation) + pub requests: BTreeMap>, + /// Sum of pending revocation amounts + bond less amounts + pub less_total: Balance, + } + + impl Default for PendingDelegationRequests { + fn default() -> PendingDelegationRequests { + PendingDelegationRequests { + revocations_count: 0u32, + requests: BTreeMap::new(), + less_total: B::zero(), } - None } } + impl< + A: Ord + Clone, + B: Zero + + Ord + + Copy + + Clone + + sp_std::ops::AddAssign + + sp_std::ops::Add + + sp_std::ops::SubAssign + + sp_std::ops::Sub, + > PendingDelegationRequests + { + /// New default (empty) pending requests + pub fn new() -> PendingDelegationRequests { + PendingDelegationRequests::default() + } + /// Add bond less order to pending requests, only succeeds if returns true + /// - limit is the maximum amount allowed that can be subtracted from the delegation + /// before it would be below the minimum delegation amount + pub fn bond_less( + &mut self, + collator: A, + amount: B, + when_executable: RoundIndex, + ) -> DispatchResult { + ensure!( + self.requests.get(&collator).is_none(), + Error::::PendingDelegationRequestAlreadyExists + ); + self.requests.insert( + collator.clone(), + DelegationRequest { + collator, + amount, + when_executable, + action: DelegationChange::Decrease, + }, + ); + self.less_total += amount; + Ok(()) + } + /// Add revoke order to pending requests + /// - limit is the maximum amount allowed that can be subtracted from the delegation + /// before it would be below the minimum delegation amount + pub fn revoke( + &mut self, + collator: A, + amount: B, + when_executable: RoundIndex, + ) -> DispatchResult { + ensure!( + self.requests.get(&collator).is_none(), + Error::::PendingDelegationRequestAlreadyExists + ); + self.requests.insert( + collator.clone(), + DelegationRequest { + collator, + amount, + when_executable, + action: DelegationChange::Revoke, + }, + ); + self.revocations_count += 1u32; + self.less_total += amount; + Ok(()) + } + } + + #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo)] + /// DEPRECATED in favor of Delegator + /// Nominator state + pub struct Nominator2 { + /// All current delegations + pub delegations: OrderedSet>, + /// Delegations scheduled to be revoked + pub revocations: OrderedSet, + /// Total balance locked for this nominator + pub total: Balance, + /// Total number of revocations scheduled to be executed + pub scheduled_revocations_count: u32, + /// Total amount to be unbonded once revocations are executed + pub scheduled_revocations_total: Balance, + /// Status for this nominator + pub status: DelegatorStatus, + } + + // /// Temporary function to migrate state + // pub(crate) fn migrate_nominator_to_delegator_state( + // id: T::AccountId, + // nominator: Nominator2>, + // ) -> Delegator> { + // Delegator { + // id, + // delegations: nominator.delegations, + // total: nominator.total, + // requests: PendingDelegationRequests::new(), + // status: nominator.status, + // } + // } + #[derive(Copy, Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)] /// The current round index and transition information pub struct RoundInfo { @@ -642,69 +1840,17 @@ pub mod pallet { /// Percent of inflation set aside for parachain bond account pub percent: Percent, } - impl Default for ParachainBondConfig { + impl Default for ParachainBondConfig { fn default() -> ParachainBondConfig { ParachainBondConfig { - account: A::default(), + account: A::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()) + .expect("infinite length input; no invalid inputs for type; qed"), percent: Percent::zero(), } } } - #[derive(Encode, Decode, RuntimeDebug, Default, TypeInfo)] - /// Store and process all delayed exits by collators and nominators - pub struct ExitQ { - /// Candidate exit set - pub candidates: OrderedSet, - /// Nominator exit set (does not include nominators that made `revoke` requests) - pub nominators_leaving: OrderedSet, - /// [Candidate, Round to Exit] - pub candidate_schedule: Vec<(AccountId, RoundIndex)>, - /// [Nominator, Some(ValidatorId) || None => All Nominations, Round To Exit] - pub nominator_schedule: Vec<(AccountId, Option, RoundIndex)>, - } - - impl ExitQ { - /// Schedule to leave the set of candidates and return all ongoing nominations - pub fn schedule_candidate_exit( - &mut self, - candidate: A, - exit_round: RoundIndex, - ) -> DispatchResult { - ensure!( - self.candidates.insert(candidate.clone()), - Error::::CandidateAlreadyLeaving - ); - self.candidate_schedule.push((candidate, exit_round)); - Ok(()) - } - /// Schedule to leave the set of nominators and revoke all ongoing nominations - pub fn schedule_nominator_exit( - &mut self, - nominator: A, - exit_round: RoundIndex, - ) -> DispatchResult { - ensure!( - self.nominators_leaving.insert(nominator.clone()), - Error::::NominatorAlreadyLeaving - ); - self.nominator_schedule.push((nominator, None, exit_round)); - Ok(()) - } - /// Schedule to revoke a single nomination - pub fn schedule_nomination_revocation( - &mut self, - nominator: A, - collator: A, - exit_round: RoundIndex, - ) -> DispatchResult { - self.nominator_schedule - .push((nominator, Some(collator), exit_round)); - Ok(()) - } - } - - type RoundIndex = u32; + pub(crate) type RoundIndex = u32; type RewardPoint = u32; pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; @@ -724,78 +1870,101 @@ pub mod pallet { /// Default number of blocks per round at genesis #[pallet::constant] type DefaultBlocksPerRound: Get; - /// Number of rounds that collators remain bonded before exit request is executed + /// Number of rounds that candidates remain bonded before exit request is executable #[pallet::constant] type LeaveCandidatesDelay: Get; - /// Number of rounds that nominators remain bonded before exit request is executed + /// Number of rounds candidate requests to decrease self-bond must wait to be executable + #[pallet::constant] + type CandidateBondLessDelay: Get; + /// Number of rounds that delegators remain bonded before exit request is executable #[pallet::constant] - type LeaveNominatorsDelay: Get; - /// Number of rounds that nominations remain bonded before revocation request is executed + type LeaveDelegatorsDelay: Get; + /// Number of rounds that delegations remain bonded before revocation request is executable #[pallet::constant] - type RevokeNominationDelay: Get; + type RevokeDelegationDelay: Get; + /// Number of rounds that delegation less requests must wait before executable + #[pallet::constant] + type DelegationBondLessDelay: Get; /// Number of rounds after which block authors are rewarded #[pallet::constant] type RewardPaymentDelay: Get; /// Minimum number of selected candidates every round #[pallet::constant] type MinSelectedCandidates: Get; - /// Maximum nominators counted per collator + /// Maximum top delegations counted per candidate + #[pallet::constant] + type MaxTopDelegationsPerCandidate: Get; + /// Maximum bottom delegations (not counted) per candidate #[pallet::constant] - type MaxNominatorsPerCollator: Get; - /// Maximum collators per nominator + type MaxBottomDelegationsPerCandidate: Get; + /// Maximum delegations per delegator #[pallet::constant] - type MaxCollatorsPerNominator: Get; - /// Default commission due to collators, set at genesis + type MaxDelegationsPerDelegator: Get; + /// Default commission due to collators, is `CollatorCommission` storage value in genesis #[pallet::constant] type DefaultCollatorCommission: Get; /// Default percent of inflation set aside for parachain bond account #[pallet::constant] type DefaultParachainBondReservePercent: Get; - /// Minimum stake required for any account to be in `SelectedCandidates` for the round + /// Minimum stake required for any candidate to be in `SelectedCandidates` for the round #[pallet::constant] type MinCollatorStk: Get>; /// Minimum stake required for any account to be a collator candidate #[pallet::constant] - type MinCollatorCandidateStk: Get>; - /// Minimum stake for any registered on-chain account to nominate + type MinCandidateStk: Get>; + /// Minimum stake for any registered on-chain account to delegate #[pallet::constant] - type MinNomination: Get>; - /// Minimum stake for any registered on-chain account to become a nominator + type MinDelegation: Get>; + /// Minimum stake for any registered on-chain account to be a delegator #[pallet::constant] - type MinNominatorStk: Get>; + type MinDelegatorStk: Get>; /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; } #[pallet::error] pub enum Error { - NominatorDNE, - NominatorDNEinTopNorBottom, - NominatorDNEInNominatorSet, + DelegatorDNE, + DelegatorDNEinTopNorBottom, + DelegatorDNEInDelegatorSet, CandidateDNE, - NominationDNE, - NominatorExists, + DelegationDNE, + DelegatorExists, CandidateExists, - ValBondBelowMin, - NomBondBelowMin, - NominationBelowMin, + CandidateBondBelowMin, + InsufficientBalance, + DelegatorBondBelowMin, + DelegationBelowMin, AlreadyOffline, AlreadyActive, - NominatorAlreadyLeaving, - NominationAlreadyRevoked, + DelegatorAlreadyLeaving, + DelegatorNotLeaving, + DelegatorCannotLeaveYet, + CannotDelegateIfLeaving, CandidateAlreadyLeaving, - CannotActBecauseLeaving, - CannotActBecauseRevoking, - ExceedMaxCollatorsPerNom, - AlreadyNominatedCollator, + CandidateNotLeaving, + CandidateCannotLeaveYet, + CannotGoOnlineIfLeaving, + ExceedMaxDelegationsPerDelegator, + AlreadyDelegatedCandidate, InvalidSchedule, CannotSetBelowMin, + RoundLengthMustBeAtLeastTotalSelectedCollators, NoWritingSameValue, TooLowCandidateCountWeightHintJoinCandidates, - TooLowCollatorCandidateCountToLeaveCandidates, - TooLowNominationCountToNominate, - TooLowCollatorNominationCountToNominate, - TooLowNominationCountToLeaveNominators, + TooLowCandidateCountWeightHintCancelLeaveCandidates, + TooLowCandidateCountToLeaveCandidates, + TooLowDelegationCountToDelegate, + TooLowCandidateDelegationCountToDelegate, + TooLowCandidateDelegationCountToLeaveCandidates, + TooLowDelegationCountToLeaveDelegators, + PendingCandidateRequestsDNE, + PendingCandidateRequestAlreadyExists, + PendingCandidateRequestNotDueYet, + PendingDelegationRequestDNE, + PendingDelegationRequestAlreadyExists, + PendingDelegationRequestNotDueYet, + CannotDelegateLessThanLowestBottomWhenBottomIsFull, } #[pallet::event] @@ -805,38 +1974,56 @@ pub mod pallet { NewRound(T::BlockNumber, RoundIndex, u32, BalanceOf), /// Account, Amount Locked, New Total Amt Locked JoinedCollatorCandidates(T::AccountId, BalanceOf, BalanceOf), - /// Round, Collator Account, Total Exposed Amount (includes all nominations) + /// Round, Collator Account, Total Exposed Amount (includes all delegations) CollatorChosen(RoundIndex, T::AccountId, BalanceOf), - /// Collator Account, Old Bond, New Bond - CollatorBondedMore(T::AccountId, BalanceOf, BalanceOf), - /// Collator Account, Old Bond, New Bond - CollatorBondedLess(T::AccountId, BalanceOf, BalanceOf), - CollatorWentOffline(RoundIndex, T::AccountId), - CollatorBackOnline(RoundIndex, T::AccountId), - /// Round, Collator Account, Scheduled Exit - CollatorScheduledExit(RoundIndex, T::AccountId, RoundIndex), - /// Account, Amount Unlocked, New Total Amt Locked - CollatorLeft(T::AccountId, BalanceOf, BalanceOf), - // Nominator, Collator, Amount, If in top nominations for collator after increase - NominationIncreased(T::AccountId, T::AccountId, BalanceOf, bool), - // Nominator, Collator, Amount, If in top nominations for collator after decrease - NominationDecreased(T::AccountId, T::AccountId, BalanceOf, bool), - /// Round, Nominator, Scheduled Exit - NominatorExitScheduled(RoundIndex, T::AccountId, RoundIndex), - /// Round, Nominator, Collator, Scheduled Exit - NominationRevocationScheduled(RoundIndex, T::AccountId, T::AccountId, RoundIndex), - /// Nominator, Amount Unstaked - NominatorLeft(T::AccountId, BalanceOf), - /// Nominator, Amount Locked, Collator, Nominator Position with New Total Counted if in Top - Nomination( + /// Candidate, Amount To Decrease, Round at which request can be executed by caller + CandidateBondLessRequested(T::AccountId, BalanceOf, RoundIndex), + /// Candidate, Amount, New Bond Total + CandidateBondedMore(T::AccountId, BalanceOf, BalanceOf), + /// Candidate, Amount, New Bond + CandidateBondedLess(T::AccountId, BalanceOf, BalanceOf), + /// Candidate + CandidateWentOffline(T::AccountId), + /// Candidate + CandidateBackOnline(T::AccountId), + /// Round At Which Exit Is Allowed, Candidate, Scheduled Exit + CandidateScheduledExit(RoundIndex, T::AccountId, RoundIndex), + /// Candidate + CancelledCandidateExit(T::AccountId), + /// Candidate, Amount, Round at which could be executed + CancelledCandidateBondLess(T::AccountId, BalanceOf, RoundIndex), + /// Ex-Candidate, Amount Unlocked, New Total Amt Locked + CandidateLeft(T::AccountId, BalanceOf, BalanceOf), + /// Delegator, Candidate, Amount to be decreased, Round at which can be executed + DelegationDecreaseScheduled(T::AccountId, T::AccountId, BalanceOf, RoundIndex), + // Delegator, Candidate, Amount, If in top delegations for candidate after increase + DelegationIncreased(T::AccountId, T::AccountId, BalanceOf, bool), + // Delegator, Candidate, Amount, If in top delegations for candidate after decrease + DelegationDecreased(T::AccountId, T::AccountId, BalanceOf, bool), + /// Round, Delegator, Scheduled Exit + DelegatorExitScheduled(RoundIndex, T::AccountId, RoundIndex), + /// Round, Delegator, Candidate, Scheduled Exit + DelegationRevocationScheduled(RoundIndex, T::AccountId, T::AccountId, RoundIndex), + /// Delegator, Amount Unstaked + DelegatorLeft(T::AccountId, BalanceOf), + /// Delegator, Candidate, Amount Unstaked + DelegationRevoked(T::AccountId, T::AccountId, BalanceOf), + /// Delegator, Candidate, Amount Unstaked + DelegationKicked(T::AccountId, T::AccountId, BalanceOf), + /// Delegator + DelegatorExitCancelled(T::AccountId), + /// Delegator, Cancelled Request + CancelledDelegationRequest(T::AccountId, DelegationRequest>), + /// Delegator, Amount Locked, Candidate, Delegator Position with New Total Counted if in Top + Delegation( T::AccountId, BalanceOf, T::AccountId, - NominatorAdded>, + DelegatorAdded>, ), - /// Nominator, Collator, Amount Unstaked, New Total Amt Staked for Collator - NominatorLeftCollator(T::AccountId, T::AccountId, BalanceOf, BalanceOf), - /// Paid the account (nominator or collator) the balance as liquid rewards + /// Delegator, Candidate, Amount Unstaked, New Total Amt Staked for Candidate + DelegatorLeftCandidate(T::AccountId, T::AccountId, BalanceOf, BalanceOf), + /// Paid the account (delegator or collator) the balance as liquid rewards Rewarded(T::AccountId, BalanceOf), /// Transferred to account which holds funds reserved for parachain bond ReservedForParachainBond(T::AccountId, BalanceOf), @@ -867,18 +2054,16 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(n: T::BlockNumber) -> Weight { + let mut weight = T::WeightInfo::base_on_initialize(); + let mut round = >::get(); if round.should_update(n) { // mutate round round.update(n); // pay all stakers for T::RewardPaymentDelay rounds ago - Self::pay_stakers(round.current); - // execute all delayed collator exits - Self::execute_collator_exits(round.current); - // execute all delayed nominator exits - Self::execute_nominator_exits(round.current); + Self::prepare_staking_payouts(round.current); // select top collator candidates for next round - let (collator_count, nomination_count, total_staked) = + let (collator_count, delegation_count, total_staked) = Self::select_top_candidates(round.current); // start next round >::put(round); @@ -890,10 +2075,15 @@ pub mod pallet { collator_count, total_staked, )); - T::WeightInfo::active_on_initialize(collator_count, nomination_count) - } else { - T::WeightInfo::passive_on_initialize() + weight += T::WeightInfo::round_transition_on_initialize( + collator_count, + delegation_count, + ); } + + weight += Self::handle_delayed_payouts(round.current); + + weight } } @@ -903,34 +2093,87 @@ pub mod pallet { type CollatorCommission = StorageValue<_, Perbill, ValueQuery>; #[pallet::storage] - #[pallet::getter(fn total_selected)] - /// The total candidates selected every round - type TotalSelected = StorageValue<_, u32, ValueQuery>; + #[pallet::getter(fn total_selected)] + /// The total candidates selected every round + type TotalSelected = StorageValue<_, u32, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn parachain_bond_info)] + /// Parachain bond config info { account, percent_of_inflation } + type ParachainBondInfo = + StorageValue<_, ParachainBondConfig, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn round)] + /// Current round index and next round scheduled transition + pub(crate) type Round = StorageValue<_, RoundInfo, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn nominator_state2)] + /// DEPRECATED in favor of DelegatorState + /// Get nominator state associated with an account if account is nominating else None + pub(crate) type NominatorState2 = StorageMap< + _, + Twox64Concat, + T::AccountId, + Nominator2>, + OptionQuery, + >; + + #[pallet::storage] + #[pallet::getter(fn delegator_state)] + /// Get delegator state associated with an account if account is delegating else None + pub(crate) type DelegatorState = StorageMap< + _, + Twox64Concat, + T::AccountId, + Delegator>, + OptionQuery, + >; + + #[pallet::storage] + #[pallet::getter(fn candidate_state)] + /// DEPRECATED + /// Get collator candidate state associated with an account if account is a candidate else None + pub(crate) type CandidateState = StorageMap< + _, + Twox64Concat, + T::AccountId, + CollatorCandidate>, + OptionQuery, + >; #[pallet::storage] - #[pallet::getter(fn parachain_bond_info)] - /// Parachain bond config info { account, percent_of_inflation } - type ParachainBondInfo = - StorageValue<_, ParachainBondConfig, ValueQuery>; + #[pallet::getter(fn candidate_info)] + /// Get collator candidate info associated with an account if account is candidate else None + pub(crate) type CandidateInfo = + StorageMap<_, Twox64Concat, T::AccountId, CandidateMetadata>, OptionQuery>; #[pallet::storage] - #[pallet::getter(fn round)] - /// Current round index and next round scheduled transition - type Round = StorageValue<_, RoundInfo, ValueQuery>; + #[pallet::getter(fn top_delegations)] + /// Top delegations for collator candidate + pub(crate) type TopDelegations = StorageMap< + _, + Twox64Concat, + T::AccountId, + Delegations>, + OptionQuery, + >; #[pallet::storage] - #[pallet::getter(fn nominator_state2)] - /// Get nominator state associated with an account if account is nominating else None - type NominatorState2 = StorageMap< + #[pallet::getter(fn bottom_delegations)] + /// Bottom delegations for collator candidate + pub(crate) type BottomDelegations = StorageMap< _, Twox64Concat, T::AccountId, - Nominator2>, + Delegations>, OptionQuery, >; #[pallet::storage] #[pallet::getter(fn collator_state2)] + /// DEPRECATED in favor of CandidateState /// Get collator state associated with an account if account is collating else None pub(crate) type CollatorState2 = StorageMap< _, @@ -948,22 +2191,17 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn total)] /// Total capital locked by this staking pallet - type Total = StorageValue<_, BalanceOf, ValueQuery>; + pub(crate) type Total = StorageValue<_, BalanceOf, ValueQuery>; #[pallet::storage] #[pallet::getter(fn candidate_pool)] /// The pool of collator candidates, each with their total backing stake - type CandidatePool = + pub(crate) type CandidatePool = StorageValue<_, OrderedSet>>, ValueQuery>; - #[pallet::storage] - #[pallet::getter(fn exit_queue2)] - /// A queue of collators and nominators awaiting exit - type ExitQueue2 = StorageValue<_, ExitQ, ValueQuery>; - #[pallet::storage] #[pallet::getter(fn at_stake)] - /// Snapshot of collator nomination stake at the start of the round + /// Snapshot of collator delegation stake at the start of the round pub type AtStake = StorageDoubleMap< _, Twox64Concat, @@ -974,9 +2212,15 @@ pub mod pallet { ValueQuery, >; + #[pallet::storage] + #[pallet::getter(fn delayed_payouts)] + /// Delayed payouts + pub type DelayedPayouts = + StorageMap<_, Twox64Concat, RoundIndex, DelayedPayout>, OptionQuery>; + #[pallet::storage] #[pallet::getter(fn staked)] - /// Total backing stake for selected candidates in the round + /// Total counted stake for selected candidates in the round pub type Staked = StorageMap<_, Twox64Concat, RoundIndex, BalanceOf, ValueQuery>; @@ -1007,7 +2251,8 @@ pub mod pallet { #[pallet::genesis_config] pub struct GenesisConfig { pub candidates: Vec<(T::AccountId, BalanceOf)>, - pub nominations: Vec<(T::AccountId, T::AccountId, BalanceOf)>, + /// Vec of tuples of the format (delegator AccountId, collator AccountId, delegation Amount) + pub delegations: Vec<(T::AccountId, T::AccountId, BalanceOf)>, pub inflation_config: InflationInfo>, } @@ -1016,7 +2261,7 @@ pub mod pallet { fn default() -> Self { Self { candidates: vec![], - nominations: vec![], + delegations: vec![], ..Default::default() } } @@ -1030,7 +2275,7 @@ pub mod pallet { // Initialize the candidates for &(ref candidate, balance) in &self.candidates { assert!( - T::Currency::free_balance(&candidate) >= balance, + T::Currency::free_balance(candidate) >= balance, "Account does not have enough balance to bond as a candidate." ); candidate_count += 1u32; @@ -1044,42 +2289,42 @@ pub mod pallet { candidate_count += 1u32; } } - let mut col_nominator_count: BTreeMap = BTreeMap::new(); - let mut nom_nominator_count: BTreeMap = BTreeMap::new(); - // Initialize the nominations - for &(ref nominator, ref target, balance) in &self.nominations { + let mut col_delegator_count: BTreeMap = BTreeMap::new(); + let mut del_delegation_count: BTreeMap = BTreeMap::new(); + // Initialize the delegations + for &(ref delegator, ref target, balance) in &self.delegations { assert!( - T::Currency::free_balance(&nominator) >= balance, - "Account does not have enough balance to place nomination." + T::Currency::free_balance(delegator) >= balance, + "Account does not have enough balance to place delegation." ); - let cn_count = if let Some(x) = col_nominator_count.get(&target) { + let cd_count = if let Some(x) = col_delegator_count.get(target) { *x } else { 0u32 }; - let nn_count = if let Some(x) = nom_nominator_count.get(&nominator) { + let dd_count = if let Some(x) = del_delegation_count.get(delegator) { *x } else { 0u32 }; - if let Err(error) = >::nominate( - T::Origin::from(Some(nominator.clone()).into()), + if let Err(error) = >::delegate( + T::Origin::from(Some(delegator.clone()).into()), target.clone(), balance, - cn_count, - nn_count, + cd_count, + dd_count, ) { - log::warn!("Join nominators failed in genesis with error {:?}", error); + log::warn!("Delegate failed in genesis with error {:?}", error); } else { - if let Some(x) = col_nominator_count.get_mut(&target) { + if let Some(x) = col_delegator_count.get_mut(target) { *x += 1u32; } else { - col_nominator_count.insert(target.clone(), 1u32); + col_delegator_count.insert(target.clone(), 1u32); }; - if let Some(x) = nom_nominator_count.get_mut(&nominator) { + if let Some(x) = del_delegation_count.get_mut(delegator) { *x += 1u32; } else { - nom_nominator_count.insert(nominator.clone(), 1u32); + del_delegation_count.insert(delegator.clone(), 1u32); }; } } @@ -1087,8 +2332,11 @@ pub mod pallet { >::put(T::DefaultCollatorCommission::get()); // Set parachain bond config to default config >::put(ParachainBondConfig { - // must be set soon; if not => due inflation will be sent to collators/nominators - account: T::AccountId::default(), + // must be set soon; if not => due inflation will be sent to collators/delegators + account: T::AccountId::decode( + &mut sp_runtime::traits::TrailingZeroInput::zeroes(), + ) + .expect("infinite length input; no invalid inputs for type; qed"), percent: T::DefaultParachainBondReservePercent::get(), }); // Set total selected candidates to minimum config @@ -1112,9 +2360,59 @@ pub mod pallet { #[pallet::call] impl Pallet { + #[pallet::weight( + ::WeightInfo::hotfix_remove_delegation_requests(delegators.len() as u32) + )] + /// Hotfix patch to remove all delegation requests not removed during a candidate exit + pub fn hotfix_remove_delegation_requests( + origin: OriginFor, + delegators: Vec, + ) -> DispatchResultWithPostInfo { + frame_system::ensure_root(origin)?; + for delegator in delegators { + if let Some(mut state) = >::get(&delegator) { + // go through all requests and remove ones without corresponding delegation + for (candidate, request) in state.requests.requests.clone().into_iter() { + if state + .delegations + .0 + .iter() + .find(|x| x.owner == candidate) + .is_none() + { + state.requests.requests.remove(&candidate); + state.requests.less_total = + state.requests.less_total.saturating_sub(request.amount); + if matches!(request.action, DelegationChange::Revoke) { + state.requests.revocations_count -= 1u32; + } + } + } + >::insert(&delegator, state); + } // else delegator is not a delegator so no update needed + } + Ok(().into()) + } + #[pallet::weight( + ::WeightInfo::hotfix_update_candidate_pool_value(candidates.len() as u32) + )] + /// Hotfix patch to correct and update CandidatePool value for candidates that have + /// called candidate_bond_more when it did not update the CandidatePool value + pub fn hotfix_update_candidate_pool_value( + origin: OriginFor, + candidates: Vec, + ) -> DispatchResultWithPostInfo { + frame_system::ensure_root(origin)?; + for candidate in candidates { + if let Some(state) = >::get(&candidate) { + Self::update_active(candidate, state.total_counted); + } // else candidate is not a candidate so no update needed + } + Ok(().into()) + } + #[pallet::weight(::WeightInfo::set_staking_expectations())] /// Set the expectations for total staked. These expectations determine the issuance for /// the round according to logic in `fn compute_issuance` - #[pallet::weight(::WeightInfo::set_staking_expectations())] pub fn set_staking_expectations( origin: OriginFor, expectations: Range>, @@ -1135,8 +2433,8 @@ pub mod pallet { >::put(config); Ok(().into()) } - /// Set the annual inflation rate to derive per-round inflation #[pallet::weight(::WeightInfo::set_inflation())] + /// Set the annual inflation rate to derive per-round inflation pub fn set_inflation( origin: OriginFor, schedule: Range, @@ -1158,8 +2456,8 @@ pub mod pallet { >::put(config); Ok(().into()) } - /// Set the account that will hold funds set aside for parachain bond #[pallet::weight(::WeightInfo::set_parachain_bond_account())] + /// Set the account that will hold funds set aside for parachain bond pub fn set_parachain_bond_account( origin: OriginFor, new: T::AccountId, @@ -1177,8 +2475,8 @@ pub mod pallet { Self::deposit_event(Event::ParachainBondAccountSet(old, new)); Ok(().into()) } - /// Set the percent of inflation set aside for parachain bond #[pallet::weight(::WeightInfo::set_parachain_bond_reserve_percent())] + /// Set the percent of inflation set aside for parachain bond pub fn set_parachain_bond_reserve_percent( origin: OriginFor, new: Percent, @@ -1207,6 +2505,10 @@ pub mod pallet { ); let old = >::get(); ensure!(old != new, Error::::NoWritingSameValue); + ensure!( + new <= >::get().length, + Error::::RoundLengthMustBeAtLeastTotalSelectedCollators, + ); >::put(new); Self::deposit_event(Event::TotalSelectedSet(old, new)); Ok(().into()) @@ -1241,6 +2543,10 @@ pub mod pallet { let mut round = >::get(); let (now, first, old) = (round.current, round.first, round.length); ensure!(old != new, Error::::NoWritingSameValue); + ensure!( + new >= >::get(), + Error::::RoundLengthMustBeAtLeastTotalSelectedCollators, + ); round.length = new; // update per-round inflation given new rounds per year let mut inflation_config = >::get(); @@ -1258,8 +2564,8 @@ pub mod pallet { >::put(inflation_config); Ok(().into()) } - /// Join the set of collator candidates #[pallet::weight(::WeightInfo::join_candidates(*candidate_count))] + /// Join the set of collator candidates pub fn join_candidates( origin: OriginFor, bond: BalanceOf, @@ -1267,10 +2573,10 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let acc = ensure_signed(origin)?; ensure!(!Self::is_candidate(&acc), Error::::CandidateExists); - ensure!(!Self::is_nominator(&acc), Error::::NominatorExists); + ensure!(!Self::is_delegator(&acc), Error::::DelegatorExists); ensure!( - bond >= T::MinCollatorCandidateStk::get(), - Error::::ValBondBelowMin + bond >= T::MinCandidateStk::get(), + Error::::CandidateBondBelowMin ); let mut candidates = >::get(); let old_count = candidates.0.len() as u32; @@ -1286,71 +2592,161 @@ pub mod pallet { Error::::CandidateExists ); T::Currency::reserve(&acc, bond)?; - let candidate = Collator2::new(acc.clone(), bond); - >::insert(&acc, candidate); + let candidate = CandidateMetadata::new(bond); + >::insert(&acc, candidate); + let empty_delegations: Delegations> = Default::default(); + // insert empty top delegations + >::insert(&acc, empty_delegations.clone()); + // insert empty bottom delegations + >::insert(&acc, empty_delegations); >::put(candidates); let new_total = >::get().saturating_add(bond); >::put(new_total); Self::deposit_event(Event::JoinedCollatorCandidates(acc, bond, new_total)); Ok(().into()) } + #[pallet::weight(::WeightInfo::schedule_leave_candidates(*candidate_count))] /// Request to leave the set of candidates. If successful, the account is immediately - /// removed from the candidate pool to prevent selection as a collator, but unbonding is - /// executed with a delay of `T::LeaveCandidates` rounds. - #[pallet::weight(::WeightInfo::leave_candidates(*candidate_count))] - pub fn leave_candidates( + /// removed from the candidate pool to prevent selection as a collator. + pub fn schedule_leave_candidates( origin: OriginFor, candidate_count: u32, ) -> DispatchResultWithPostInfo { let collator = ensure_signed(origin)?; - let mut state = - >::get(&collator).ok_or(Error::::CandidateDNE)?; - ensure!(!state.is_leaving(), Error::::CandidateAlreadyLeaving); - let mut exits = >::get(); - let now = >::get().current; - let when = now + T::LeaveCandidatesDelay::get(); - exits.schedule_candidate_exit::(collator.clone(), when)?; - state.leave(when); + let mut state = >::get(&collator).ok_or(Error::::CandidateDNE)?; + let (now, when) = state.schedule_leave::()?; let mut candidates = >::get(); ensure!( candidate_count >= candidates.0.len() as u32, - Error::::TooLowCollatorCandidateCountToLeaveCandidates + Error::::TooLowCandidateCountToLeaveCandidates ); if candidates.remove(&Bond::from_owner(collator.clone())) { >::put(candidates); } - >::put(exits); - >::insert(&collator, state); - Self::deposit_event(Event::CollatorScheduledExit(now, collator, when)); + >::insert(&collator, state); + Self::deposit_event(Event::CandidateScheduledExit(now, collator, when)); + Ok(().into()) + } + #[pallet::weight( + ::WeightInfo::execute_leave_candidates(*candidate_delegation_count) + )] + /// Execute leave candidates request + pub fn execute_leave_candidates( + origin: OriginFor, + candidate: T::AccountId, + candidate_delegation_count: u32, + ) -> DispatchResultWithPostInfo { + ensure_signed(origin)?; + let state = >::get(&candidate).ok_or(Error::::CandidateDNE)?; + ensure!( + state.delegation_count <= candidate_delegation_count, + Error::::TooLowCandidateDelegationCountToLeaveCandidates + ); + state.can_leave::()?; + let return_stake = |bond: Bond>| { + T::Currency::unreserve(&bond.owner, bond.amount); + // remove delegation from delegator state + let mut delegator = DelegatorState::::get(&bond.owner).expect( + "Collator state and delegator state are consistent. + Collator state has a record of this delegation. Therefore, + Delegator state also has a record. qed.", + ); + if let Some(remaining) = delegator.rm_delegation(&candidate) { + if remaining.is_zero() { + >::remove(&bond.owner); + } else { + if let Some(request) = delegator.requests.requests.remove(&candidate) { + delegator.requests.less_total = + delegator.requests.less_total.saturating_sub(request.amount); + if matches!(request.action, DelegationChange::Revoke) { + delegator.requests.revocations_count -= 1u32; + } + } + >::insert(&bond.owner, delegator); + } + } + }; + // total backing stake is at least the candidate self bond + let mut total_backing = state.bond; + // return all top delegations + let top_delegations = + >::take(&candidate).expect("CandidateInfo existence checked"); + for bond in top_delegations.delegations { + return_stake(bond); + } + total_backing += top_delegations.total; + // return all bottom delegations + let bottom_delegations = >::take(&candidate) + .expect("CandidateInfo existence checked"); + for bond in bottom_delegations.delegations { + return_stake(bond); + } + total_backing += bottom_delegations.total; + // return stake to collator + T::Currency::unreserve(&candidate, state.bond); + >::remove(&candidate); + >::remove(&candidate); + >::remove(&candidate); + let new_total_staked = >::get().saturating_sub(total_backing); + >::put(new_total_staked); + Self::deposit_event(Event::CandidateLeft( + candidate, + total_backing, + new_total_staked, + )); + Ok(().into()) + } + #[pallet::weight(::WeightInfo::cancel_leave_candidates(*candidate_count))] + /// Cancel open request to leave candidates + /// - only callable by collator account + /// - result upon successful call is the candidate is active in the candidate pool + pub fn cancel_leave_candidates( + origin: OriginFor, + candidate_count: u32, + ) -> DispatchResultWithPostInfo { + let collator = ensure_signed(origin)?; + let mut state = >::get(&collator).ok_or(Error::::CandidateDNE)?; + ensure!(state.is_leaving(), Error::::CandidateNotLeaving); + state.go_online(); + let mut candidates = >::get(); + ensure!( + candidates.0.len() as u32 <= candidate_count, + Error::::TooLowCandidateCountWeightHintCancelLeaveCandidates + ); + ensure!( + candidates.insert(Bond { + owner: collator.clone(), + amount: state.total_counted + }), + Error::::AlreadyActive + ); + >::put(candidates); + >::insert(&collator, state); + Self::deposit_event(Event::CancelledCandidateExit(collator)); Ok(().into()) } - /// Temporarily leave the set of collator candidates without unbonding #[pallet::weight(::WeightInfo::go_offline())] + /// Temporarily leave the set of collator candidates without unbonding pub fn go_offline(origin: OriginFor) -> DispatchResultWithPostInfo { let collator = ensure_signed(origin)?; - let mut state = - >::get(&collator).ok_or(Error::::CandidateDNE)?; + let mut state = >::get(&collator).ok_or(Error::::CandidateDNE)?; ensure!(state.is_active(), Error::::AlreadyOffline); state.go_offline(); let mut candidates = >::get(); if candidates.remove(&Bond::from_owner(collator.clone())) { >::put(candidates); } - >::insert(&collator, state); - Self::deposit_event(Event::CollatorWentOffline( - >::get().current, - collator, - )); + >::insert(&collator, state); + Self::deposit_event(Event::CandidateWentOffline(collator)); Ok(().into()) } - /// Rejoin the set of collator candidates if previously had called `go_offline` #[pallet::weight(::WeightInfo::go_online())] + /// Rejoin the set of collator candidates if previously had called `go_offline` pub fn go_online(origin: OriginFor) -> DispatchResultWithPostInfo { let collator = ensure_signed(origin)?; - let mut state = - >::get(&collator).ok_or(Error::::CandidateDNE)?; + let mut state = >::get(&collator).ok_or(Error::::CandidateDNE)?; ensure!(!state.is_active(), Error::::AlreadyActive); - ensure!(!state.is_leaving(), Error::::CannotActBecauseLeaving); + ensure!(!state.is_leaving(), Error::::CannotGoOnlineIfLeaving); state.go_online(); let mut candidates = >::get(); ensure!( @@ -1361,317 +2757,296 @@ pub mod pallet { Error::::AlreadyActive ); >::put(candidates); - >::insert(&collator, state); - Self::deposit_event(Event::CollatorBackOnline( - >::get().current, - collator, - )); + >::insert(&collator, state); + Self::deposit_event(Event::CandidateBackOnline(collator)); Ok(().into()) } - /// Bond more for collator candidates #[pallet::weight(::WeightInfo::candidate_bond_more())] + /// Increase collator candidate self bond by `more` pub fn candidate_bond_more( origin: OriginFor, more: BalanceOf, ) -> DispatchResultWithPostInfo { let collator = ensure_signed(origin)?; - let mut state = - >::get(&collator).ok_or(Error::::CandidateDNE)?; - ensure!(!state.is_leaving(), Error::::CannotActBecauseLeaving); - T::Currency::reserve(&collator, more)?; - let before = state.bond; - state.bond_more(more); - let after = state.bond; - if state.is_active() { - Self::update_active(collator.clone(), state.total_counted); + let mut state = >::get(&collator).ok_or(Error::::CandidateDNE)?; + state.bond_more::(collator.clone(), more)?; + let (is_active, total_counted) = (state.is_active(), state.total_counted); + >::insert(&collator, state); + if is_active { + Self::update_active(collator, total_counted); } - >::insert(&collator, state); - let new_total = >::get().saturating_add(more); - >::put(new_total); - Self::deposit_event(Event::CollatorBondedMore(collator, before, after)); Ok(().into()) } - /// Bond less for collator candidates - #[pallet::weight(::WeightInfo::candidate_bond_less())] - pub fn candidate_bond_less( + #[pallet::weight(::WeightInfo::schedule_candidate_bond_less())] + /// Request by collator candidate to decrease self bond by `less` + pub fn schedule_candidate_bond_less( origin: OriginFor, less: BalanceOf, ) -> DispatchResultWithPostInfo { let collator = ensure_signed(origin)?; + let mut state = >::get(&collator).ok_or(Error::::CandidateDNE)?; + let when = state.schedule_bond_less::(less)?; + >::insert(&collator, state); + Self::deposit_event(Event::CandidateBondLessRequested(collator, less, when)); + Ok(().into()) + } + #[pallet::weight(::WeightInfo::execute_candidate_bond_less())] + /// Execute pending request to adjust the collator candidate self bond + pub fn execute_candidate_bond_less( + origin: OriginFor, + candidate: T::AccountId, + ) -> DispatchResultWithPostInfo { + ensure_signed(origin)?; // we may want to reward this if caller != candidate let mut state = - >::get(&collator).ok_or(Error::::CandidateDNE)?; - ensure!(!state.is_leaving(), Error::::CannotActBecauseLeaving); - let before = state.bond; - let after = state.bond_less(less).ok_or(Error::::ValBondBelowMin)?; - ensure!( - after >= T::MinCollatorCandidateStk::get(), - Error::::ValBondBelowMin - ); - T::Currency::unreserve(&collator, less); - if state.is_active() { - Self::update_active(collator.clone(), state.total_counted); - } - >::insert(&collator, state); - let new_total_staked = >::get().saturating_sub(less); - >::put(new_total_staked); - Self::deposit_event(Event::CollatorBondedLess(collator, before, after)); + >::get(&candidate).ok_or(Error::::CandidateDNE)?; + state.execute_bond_less::(candidate.clone())?; + >::insert(&candidate, state); + Ok(().into()) + } + #[pallet::weight(::WeightInfo::cancel_candidate_bond_less())] + /// Cancel pending request to adjust the collator candidate self bond + pub fn cancel_candidate_bond_less(origin: OriginFor) -> DispatchResultWithPostInfo { + let collator = ensure_signed(origin)?; + let mut state = >::get(&collator).ok_or(Error::::CandidateDNE)?; + state.cancel_bond_less::(collator.clone())?; + >::insert(&collator, state); Ok(().into()) } - /// If caller is not a nominator, then join the set of nominators - /// If caller is a nominator, then makes nomination to change their nomination state #[pallet::weight( - ::WeightInfo::nominate( - *collator_nominator_count, - *nomination_count + ::WeightInfo::delegate( + *candidate_delegation_count, + *delegation_count ) )] - pub fn nominate( + /// If caller is not a delegator and not a collator, then join the set of delegators + /// If caller is a delegator, then makes delegation to change their delegation state + pub fn delegate( origin: OriginFor, - collator: T::AccountId, + candidate: T::AccountId, amount: BalanceOf, - collator_nominator_count: u32, - nomination_count: u32, + // will_be_in_top: bool // weight hint + // look into returning weight in DispatchResult + candidate_delegation_count: u32, + delegation_count: u32, ) -> DispatchResultWithPostInfo { - let acc = ensure_signed(origin)?; - let nominator = if let Some(mut state) = >::get(&acc) { - ensure!(state.is_active(), Error::::CannotActBecauseLeaving); - // nomination after first + let delegator = ensure_signed(origin)?; + // check that caller can reserve the amount before any changes to storage + ensure!( + T::Currency::can_reserve(&delegator, amount), + Error::::InsufficientBalance + ); + let delegator_state = if let Some(mut state) = >::get(&delegator) { + ensure!(state.is_active(), Error::::CannotDelegateIfLeaving); + // delegation after first ensure!( - amount >= T::MinNomination::get(), - Error::::NominationBelowMin + amount >= T::MinDelegation::get(), + Error::::DelegationBelowMin ); ensure!( - nomination_count >= state.nominations.0.len() as u32, - Error::::TooLowNominationCountToNominate + delegation_count >= state.delegations.0.len() as u32, + Error::::TooLowDelegationCountToDelegate ); ensure!( - (state.nominations.0.len() as u32) < T::MaxCollatorsPerNominator::get(), - Error::::ExceedMaxCollatorsPerNom + (state.delegations.0.len() as u32) < T::MaxDelegationsPerDelegator::get(), + Error::::ExceedMaxDelegationsPerDelegator ); - // ensure that nominator is not in the exit_queue ensure!( - state.add_nomination(Bond { - owner: collator.clone(), + state.add_delegation(Bond { + owner: candidate.clone(), amount }), - Error::::AlreadyNominatedCollator + Error::::AlreadyDelegatedCandidate ); state } else { - // first nomination + // first delegation ensure!( - amount >= T::MinNominatorStk::get(), - Error::::NomBondBelowMin + amount >= T::MinDelegatorStk::get(), + Error::::DelegatorBondBelowMin ); - ensure!(!Self::is_candidate(&acc), Error::::CandidateExists); - Nominator2::new(collator.clone(), amount) + ensure!(!Self::is_candidate(&delegator), Error::::CandidateExists); + Delegator::new(delegator.clone(), candidate.clone(), amount) }; let mut state = - >::get(&collator).ok_or(Error::::CandidateDNE)?; + >::get(&candidate).ok_or(Error::::CandidateDNE)?; ensure!( - collator_nominator_count >= state.nominators.0.len() as u32, - Error::::TooLowCollatorNominationCountToNominate + candidate_delegation_count >= state.delegation_count, + Error::::TooLowCandidateDelegationCountToDelegate ); - let nominator_position = state.add_nominator::(acc.clone(), amount)?; - T::Currency::reserve(&acc, amount)?; - if let NominatorAdded::AddedToTop { new_total } = nominator_position { + let (delegator_position, less_total_staked) = state.add_delegation::( + &candidate, + Bond { + owner: delegator.clone(), + amount, + }, + )?; + T::Currency::reserve(&delegator, amount) + .expect("verified can reserve at top of this extrinsic body"); + if let DelegatorAdded::AddedToTop { new_total } = delegator_position { if state.is_active() { - Self::update_active(collator.clone(), new_total); + Self::update_active(candidate.clone(), new_total); } } - let new_total_locked = >::get() + amount; + // only is_some if kicked the lowest bottom as a consequence of this new delegation + let net_total_increase = if let Some(less) = less_total_staked { + amount - less + } else { + amount + }; + let new_total_locked = >::get() + net_total_increase; >::put(new_total_locked); - >::insert(&collator, state); - >::insert(&acc, nominator); - Self::deposit_event(Event::Nomination(acc, amount, collator, nominator_position)); + >::insert(&candidate, state); + >::insert(&delegator, delegator_state); + Self::deposit_event(Event::Delegation( + delegator, + amount, + candidate, + delegator_position, + )); + Ok(().into()) + } + #[pallet::weight(::WeightInfo::schedule_leave_delegators())] + /// Request to leave the set of delegators. If successful, the caller is scheduled + /// to be allowed to exit. Success forbids future delegator actions until the request is + /// invoked or cancelled. + pub fn schedule_leave_delegators(origin: OriginFor) -> DispatchResultWithPostInfo { + let acc = ensure_signed(origin)?; + let mut state = >::get(&acc).ok_or(Error::::DelegatorDNE)?; + ensure!(!state.is_leaving(), Error::::DelegatorAlreadyLeaving); + let (now, when) = state.schedule_leave::(); + >::insert(&acc, state); + Self::deposit_event(Event::DelegatorExitScheduled(now, acc, when)); Ok(().into()) } - /// Request to leave the set of nominators. If successful, the nominator is scheduled - /// to exit - #[pallet::weight(::WeightInfo::leave_nominators(*nomination_count))] - pub fn leave_nominators( + #[pallet::weight(::WeightInfo::execute_leave_delegators(*delegation_count))] + /// Execute the right to exit the set of delegators and revoke all ongoing delegations. + pub fn execute_leave_delegators( origin: OriginFor, - nomination_count: u32, + delegator: T::AccountId, + delegation_count: u32, ) -> DispatchResultWithPostInfo { - let acc = ensure_signed(origin)?; - let mut state = >::get(&acc).ok_or(Error::::NominatorDNE)?; - ensure!(!state.is_leaving(), Error::::NominatorAlreadyLeaving); - ensure!( - nomination_count >= (state.nominations.0.len() as u32), - Error::::TooLowNominationCountToLeaveNominators - ); - let mut exits = >::get(); - let now = >::get().current; - let when = now + T::LeaveNominatorsDelay::get(); - exits.schedule_nominator_exit::(acc.clone(), when)?; - state.leave(when); - state.scheduled_revocations_total = state.total; - state.scheduled_revocations_count = state.nominations.0.len() as u32; - >::put(exits); - >::insert(&acc, state); - Self::deposit_event(Event::NominatorExitScheduled(now, acc, when)); + ensure_signed(origin)?; + let state = >::get(&delegator).ok_or(Error::::DelegatorDNE)?; + state.can_execute_leave::(delegation_count)?; + for bond in state.delegations.0 { + if let Err(error) = Self::delegator_leaves_candidate( + bond.owner.clone(), + delegator.clone(), + bond.amount, + ) { + log::warn!( + "STORAGE CORRUPTED \nDelegator leaving collator failed with error: {:?}", + error + ); + } + } + >::remove(&delegator); + Self::deposit_event(Event::DelegatorLeft(delegator, state.total)); + Ok(().into()) + } + #[pallet::weight(::WeightInfo::cancel_leave_delegators())] + /// Cancel a pending request to exit the set of delegators. Success clears the pending exit + /// request (thereby resetting the delay upon another `leave_delegators` call). + pub fn cancel_leave_delegators(origin: OriginFor) -> DispatchResultWithPostInfo { + let delegator = ensure_signed(origin)?; + // ensure delegator state exists + let mut state = + >::get(&delegator).ok_or(Error::::DelegatorDNE)?; + // ensure state is leaving + ensure!(state.is_leaving(), Error::::DelegatorDNE); + // cancel exit request + state.cancel_leave(); + >::insert(&delegator, state); + Self::deposit_event(Event::DelegatorExitCancelled(delegator)); Ok(().into()) } - /// Request to revoke an existing nomination. If successful, the nomination is scheduled - /// to exit - #[pallet::weight(::WeightInfo::revoke_nomination())] - pub fn revoke_nomination( + #[pallet::weight(::WeightInfo::schedule_revoke_delegation())] + /// Request to revoke an existing delegation. If successful, the delegation is scheduled + /// to be allowed to be revoked via the `execute_delegation_request` extrinsic. + pub fn schedule_revoke_delegation( origin: OriginFor, collator: T::AccountId, ) -> DispatchResultWithPostInfo { - let nominator = ensure_signed(origin)?; + let delegator = ensure_signed(origin)?; let mut state = - >::get(&nominator).ok_or(Error::::NominatorDNE)?; - ensure!(state.is_active(), Error::::CannotActBecauseLeaving); - ensure!( - state.revocations.insert(collator.clone()), - Error::::NominationAlreadyRevoked - ); - let mut nomination_amount: Option> = None; - for Bond { owner, amount } in state.nominations.0.iter() { - if owner == &collator { - nomination_amount = Some(*amount); - break; - } - } - // Ensure that the collator exists in the nominations - let amount = nomination_amount.ok_or(Error::::NominationDNE)?; - let remaining = state.total - state.scheduled_revocations_total - amount; - let leaving = - if state.nominations.0.len() as u32 - state.scheduled_revocations_count < 2 { - true - } else { - ensure!( - remaining >= T::MinNominatorStk::get(), - Error::::NomBondBelowMin - ); - false - }; - let mut exits = >::get(); - let now = >::get().current; - let when = now + T::RevokeNominationDelay::get(); - if leaving { - // schedule to leave the set of nominators if this is the only nomination - exits.schedule_nominator_exit::(nominator.clone(), when)?; - state.leave(when); - state.scheduled_revocations_total = state.total; - state.scheduled_revocations_count = state.nominations.0.len() as u32; - >::put(exits); - >::insert(&nominator, state); - Self::deposit_event(Event::NominatorExitScheduled(now, nominator, when)); - } else { - // schedule to revoke this nomination - exits.schedule_nomination_revocation::( - nominator.clone(), - collator.clone(), - when, - )?; - state.scheduled_revocations_total += amount; - state.scheduled_revocations_count += 1u32; - >::put(exits); - >::insert(&nominator, state); - Self::deposit_event(Event::NominationRevocationScheduled( - now, nominator, collator, when, - )); - } + >::get(&delegator).ok_or(Error::::DelegatorDNE)?; + let (now, when) = state.schedule_revoke::(collator.clone())?; + >::insert(&delegator, state); + Self::deposit_event(Event::DelegationRevocationScheduled( + now, delegator, collator, when, + )); Ok(().into()) } - /// Bond more for nominators with respect to a specific collator candidate - #[pallet::weight(::WeightInfo::nominator_bond_more())] - pub fn nominator_bond_more( + #[pallet::weight(::WeightInfo::delegator_bond_more())] + /// Bond more for delegators wrt a specific collator candidate. + pub fn delegator_bond_more( origin: OriginFor, candidate: T::AccountId, more: BalanceOf, ) -> DispatchResultWithPostInfo { - let nominator = ensure_signed(origin)?; + let delegator = ensure_signed(origin)?; let mut state = - >::get(&nominator).ok_or(Error::::NominatorDNE)?; - ensure!(state.is_active(), Error::::CannotActBecauseLeaving); - ensure!( - !state.revocations.contains(&candidate), - Error::::CannotActBecauseRevoking - ); - let mut collator = - >::get(&candidate).ok_or(Error::::CandidateDNE)?; - ensure!( - state.inc_nomination(candidate.clone(), more), - Error::::NominationDNE - ); - T::Currency::reserve(&nominator, more)?; - let before = collator.total_counted; - let in_top = collator.inc_nominator(nominator.clone(), more); - let after = collator.total_counted; - if collator.is_active() && (before != after) { - Self::update_active(candidate.clone(), after); - } - >::insert(&candidate, collator); - >::insert(&nominator, state); - let new_total_staked = >::get().saturating_add(more); - >::put(new_total_staked); - Self::deposit_event(Event::NominationIncreased( - nominator, candidate, more, in_top, - )); + >::get(&delegator).ok_or(Error::::DelegatorDNE)?; + state.increase_delegation::(candidate.clone(), more)?; Ok(().into()) } - /// Bond less for nominators with respect to a specific nominator candidate - #[pallet::weight(::WeightInfo::nominator_bond_less())] - pub fn nominator_bond_less( + #[pallet::weight(::WeightInfo::schedule_delegator_bond_less())] + /// Request bond less for delegators wrt a specific collator candidate. + pub fn schedule_delegator_bond_less( origin: OriginFor, candidate: T::AccountId, less: BalanceOf, ) -> DispatchResultWithPostInfo { - let nominator = ensure_signed(origin)?; - let mut state = - >::get(&nominator).ok_or(Error::::NominatorDNE)?; - ensure!(state.is_active(), Error::::CannotActBecauseLeaving); - ensure!( - !state.revocations.contains(&candidate), - Error::::CannotActBecauseRevoking - ); - let mut collator = - >::get(&candidate).ok_or(Error::::CandidateDNE)?; - let remaining = state - .dec_nomination(candidate.clone(), less) - .ok_or(Error::::NominationDNE)? - .ok_or(Error::::NomBondBelowMin)?; - ensure!( - remaining >= T::MinNomination::get(), - Error::::NominationBelowMin - ); - ensure!( - state.total >= T::MinNominatorStk::get(), - Error::::NomBondBelowMin - ); - T::Currency::unreserve(&nominator, less); - let before = collator.total_counted; - let in_top = collator.dec_nominator(nominator.clone(), less); - let after = collator.total_counted; - if collator.is_active() && (before != after) { - Self::update_active(candidate.clone(), after); - } - >::insert(&candidate, collator); - >::insert(&nominator, state); - let new_total_staked = >::get().saturating_sub(less); - >::put(new_total_staked); - Self::deposit_event(Event::NominationDecreased( - nominator, candidate, less, in_top, + let caller = ensure_signed(origin)?; + let mut state = >::get(&caller).ok_or(Error::::DelegatorDNE)?; + let when = state.schedule_decrease_delegation::(candidate.clone(), less)?; + >::insert(&caller, state); + Self::deposit_event(Event::DelegationDecreaseScheduled( + caller, candidate, less, when, )); Ok(().into()) } + #[pallet::weight(::WeightInfo::execute_delegator_bond_less())] + /// Execute pending request to change an existing delegation + pub fn execute_delegation_request( + origin: OriginFor, + delegator: T::AccountId, + candidate: T::AccountId, + ) -> DispatchResultWithPostInfo { + ensure_signed(origin)?; // we may want to reward caller if caller != delegator + let mut state = + >::get(&delegator).ok_or(Error::::DelegatorDNE)?; + state.execute_pending_request::(candidate)?; + Ok(().into()) + } + #[pallet::weight(::WeightInfo::cancel_delegator_bond_less())] + /// Cancel request to change an existing delegation. + pub fn cancel_delegation_request( + origin: OriginFor, + candidate: T::AccountId, + ) -> DispatchResultWithPostInfo { + let delegator = ensure_signed(origin)?; + let mut state = + >::get(&delegator).ok_or(Error::::DelegatorDNE)?; + let request = state.cancel_pending_request::(candidate)?; + >::insert(&delegator, state); + Self::deposit_event(Event::CancelledDelegationRequest(delegator, request)); + Ok(().into()) + } } impl Pallet { - pub fn is_nominator(acc: &T::AccountId) -> bool { - >::get(acc).is_some() + pub fn is_delegator(acc: &T::AccountId) -> bool { + >::get(acc).is_some() } pub fn is_candidate(acc: &T::AccountId) -> bool { - >::get(acc).is_some() + >::get(acc).is_some() } pub fn is_selected_candidate(acc: &T::AccountId) -> bool { >::get().binary_search(acc).is_ok() } - // ensure candidate is active before calling - fn update_active(candidate: T::AccountId, total: BalanceOf) { + /// Caller must ensure candidate is active before calling + pub(crate) fn update_active(candidate: T::AccountId, total: BalanceOf) { let mut candidates = >::get(); candidates.remove(&Bond::from_owner(candidate.clone())); candidates.insert(Bond { @@ -1680,7 +3055,7 @@ pub mod pallet { }); >::put(candidates); } - // Calculate round issuance based on total staked for the given round + /// Compute round issuance based on total staked for the given round fn compute_issuance(staked: BalanceOf) -> BalanceOf { let config = >::get(); let round_issuance = crate::inflation::round_issuance_range::(config.round); @@ -1693,41 +3068,42 @@ pub mod pallet { round_issuance.ideal } } - pub(crate) fn nominator_leaves_collator( - nominator: T::AccountId, - collator: T::AccountId, - ) -> DispatchResultWithPostInfo { + /// Remove delegation from candidate state + /// Amount input should be retrieved from delegator and it informs the storage lookups + fn delegator_leaves_candidate( + candidate: T::AccountId, + delegator: T::AccountId, + amount: BalanceOf, + ) -> DispatchResult { let mut state = - >::get(&collator).ok_or(Error::::CandidateDNE)?; - let (total_changed, nominator_stake) = state.rm_nominator::(nominator.clone())?; - T::Currency::unreserve(&nominator, nominator_stake); + >::get(&candidate).ok_or(Error::::CandidateDNE)?; + let total_changed = + state.rm_delegation_if_exists::(&candidate, delegator.clone(), amount)?; + T::Currency::unreserve(&delegator, amount); if state.is_active() && total_changed { - Self::update_active(collator.clone(), state.total_counted); + Self::update_active(candidate.clone(), state.total_counted); } - let new_total_locked = >::get() - nominator_stake; + let new_total_locked = >::get().saturating_sub(amount); >::put(new_total_locked); let new_total = state.total_counted; - >::insert(&collator, state); - Self::deposit_event(Event::NominatorLeftCollator( - nominator, - collator, - nominator_stake, - new_total, + >::insert(&candidate, state); + Self::deposit_event(Event::DelegatorLeftCandidate( + delegator, candidate, amount, new_total, )); - Ok(().into()) + Ok(()) } - fn pay_stakers(next: RoundIndex) { - // payout is next - duration rounds ago => next - duration > 0 else return early - let duration = T::RewardPaymentDelay::get(); - if next <= duration { + fn prepare_staking_payouts(now: RoundIndex) { + // payout is now - delay rounds ago => now - delay > 0 else return early + let delay = T::RewardPaymentDelay::get(); + if now <= delay { return; } - let round_to_payout = next - duration; - let total = >::get(round_to_payout); - if total.is_zero() { + let round_to_payout = now - delay; + let total_points = >::get(round_to_payout); + if total_points.is_zero() { return; } - let total_staked = >::get(round_to_payout); + let total_staked = >::take(round_to_payout); let total_issuance = Self::compute_issuance(total_staked); let mut left_issuance = total_issuance; // reserve portion of issuance for parachain bond account @@ -1743,187 +3119,118 @@ pub mod pallet { imb.peek(), )); } - let mint = |amt: BalanceOf, to: T::AccountId| { - if let Ok(imb) = T::Currency::deposit_into_existing(&to, amt) { - Self::deposit_event(Event::Rewarded(to.clone(), imb.peek())); - } + + let payout = DelayedPayout { + round_issuance: total_issuance, + total_staking_reward: left_issuance, + collator_commission: >::get(), }; - // only pay out rewards at the end to transfer only total amount due - let mut due_rewards: BTreeMap> = BTreeMap::new(); - let mut increase_due_rewards = |amt: BalanceOf, to: T::AccountId| { - if let Some(already_due) = due_rewards.get(&to) { - let amount = amt.saturating_add(*already_due); - due_rewards.insert(to, amount); - } else { - due_rewards.insert(to, amt); + + >::insert(round_to_payout, payout); + } + + /// Wrapper around pay_one_collator_reward which handles the following logic: + /// * whether or not a payout needs to be made + /// * cleaning up when payouts are done + /// * returns the weight consumed by pay_one_collator_reward if applicable + fn handle_delayed_payouts(now: RoundIndex) -> Weight { + let delay = T::RewardPaymentDelay::get(); + + // don't underflow uint + if now < delay { + return 0u64.into(); + } + + let paid_for_round = now - delay; + + if let Some(payout_info) = >::get(paid_for_round) { + let result = Self::pay_one_collator_reward(paid_for_round, payout_info); + if result.0.is_none() { + // result.0 indicates whether or not a payout was made + // clean up storage items that we no longer need + >::remove(paid_for_round); + >::remove(paid_for_round); + } + result.1 // weight consumed by pay_one_collator_reward + } else { + 0u64.into() + } + } + + /// Payout a single collator from the given round. + /// + /// Returns an optional tuple of (Collator's AccountId, total paid) + /// or None if there were no more payouts to be made for the round. + pub(crate) fn pay_one_collator_reward( + paid_for_round: RoundIndex, + payout_info: DelayedPayout>, + ) -> (Option<(T::AccountId, BalanceOf)>, Weight) { + // TODO: it would probably be optimal to roll Points into the DelayedPayouts storage + // item so that we do fewer reads each block + let total_points = >::get(paid_for_round); + if total_points.is_zero() { + // TODO: this case is obnoxious... it's a value query, so it could mean one of two + // different logic errors: + // 1. we removed it before we should have + // 2. we called pay_one_collator_reward when we were actually done with deferred + // payouts + log::warn!("pay_one_collator_reward called with no > for the round!"); + return (None, 0u64.into()); + } + + let mint = |amt: BalanceOf, to: T::AccountId| { + if let Ok(amount_transferred) = T::Currency::deposit_into_existing(&to, amt) { + Self::deposit_event(Event::Rewarded(to.clone(), amount_transferred.peek())); } }; - let collator_fee = >::get(); - let collator_issuance = collator_fee * total_issuance; - for (val, pts) in >::drain_prefix(round_to_payout) { - let pct_due = Perbill::from_rational(pts, total); - let mut amt_due = pct_due * left_issuance; - // Take the snapshot of block author and nominations - let state = >::take(round_to_payout, &val); - if state.nominators.is_empty() { - // solo collator with no nominators - mint(amt_due, val.clone()); + + let collator_fee = payout_info.collator_commission; + let collator_issuance = collator_fee * payout_info.round_issuance; + + if let Some((collator, pts)) = + >::iter_prefix(paid_for_round).drain().next() + { + let pct_due = Perbill::from_rational(pts, total_points); + let total_paid = pct_due * payout_info.total_staking_reward; + let mut amt_due = total_paid; + // Take the snapshot of block author and delegations + let state = >::take(paid_for_round, &collator); + let num_delegators = state.delegations.len(); + if state.delegations.is_empty() { + // solo collator with no delegators + mint(amt_due, collator.clone()); } else { // pay collator first; commission + due_portion - let val_pct = Perbill::from_rational(state.bond, state.total); + let collator_pct = Perbill::from_rational(state.bond, state.total); let commission = pct_due * collator_issuance; amt_due -= commission; - let val_due = (val_pct * amt_due) + commission; - mint(val_due, val.clone()); - // pay nominators due portion - for Bond { owner, amount } in state.nominators { + let collator_reward = (collator_pct * amt_due) + commission; + mint(collator_reward, collator.clone()); + // pay delegators due portion + for Bond { owner, amount } in state.delegations { let percent = Perbill::from_rational(amount, state.total); let due = percent * amt_due; - increase_due_rewards(due, owner); + mint(due, owner.clone()); } } + + ( + Some((collator, total_paid)), + T::WeightInfo::pay_one_collator_reward(num_delegators as u32), + ) + } else { + // Note that we don't clean up storage here; it is cleaned up in + // handle_delayed_payouts() + (None, 0u64.into()) } - for (nominator, total_due) in due_rewards { - mint(total_due, nominator); - } - } - /// Executes all collator exits scheduled for when <= now - fn execute_collator_exits(now: RoundIndex) { - let mut exit_queue = >::get(); - let remaining_exits = exit_queue - .candidate_schedule - .clone() - .into_iter() - .filter_map(|(who, when)| { - if when > now { - Some((who, when)) - } else { - if !exit_queue.candidates.remove(&who) { - log::warn!( - "Candidates set removal failed, CollatorState had inconsistency!", - ); - } - if let Some(state) = >::get(&who) { - // return stake to nominator - let return_stake = |bond: Bond>| { - T::Currency::unreserve(&bond.owner, bond.amount); - // remove nomination from nominator state - let mut nominator = NominatorState2::::get(&bond.owner) - .expect( - "Collator state and nominator state are consistent. - Collator state has a record of this nomination. Therefore, - Nominator state also has a record. qed.", - ); - if let Some(remaining) = nominator.rm_nomination(who.clone()) { - if remaining.is_zero() { - >::remove(&bond.owner); - } else { - >::insert(&bond.owner, nominator); - } - } - }; - // return all top nominations - for bond in state.top_nominators { - return_stake(bond); - } - // return all bottom nominations - for bond in state.bottom_nominators { - return_stake(bond); - } - // return stake to collator - T::Currency::unreserve(&state.id, state.bond); - >::remove(&who); - let new_total_staked = - >::get().saturating_sub(state.total_backing); - >::put(new_total_staked); - Self::deposit_event(Event::CollatorLeft( - who, - state.total_backing, - new_total_staked, - )); - } - None - } - }) - .collect::>(); - exit_queue.candidate_schedule = remaining_exits; - >::put(exit_queue); - } - /// Executes all nominator exits for when <= now - fn execute_nominator_exits(now: RoundIndex) { - let mut exit_queue = >::get(); - let remaining_exits = exit_queue - .nominator_schedule - .clone() - .into_iter() - .filter_map(|(nominator, maybe_collator, when)| { - if when > now { - Some((nominator, maybe_collator, when)) - } else { - if let Some(collator) = maybe_collator { - // single revocation needs to be executed - if let Some(mut state) = >::get(&nominator) { - let pre_total = state.total; - if let Some(remaining) = state.rm_nomination(collator.clone()) { - let amount = pre_total - remaining; - state.scheduled_revocations_total -= amount; - state.scheduled_revocations_count -= 1u32; - state.revocations.remove(&collator); - let _ = Self::nominator_leaves_collator( - nominator.clone(), - collator, - ); - >::insert(&nominator, state); - } - } else { - log::warn!( - "Nominator State for Nominator {:?} Not Found During Revocation - of Support for Collator {:?}", - nominator, - collator, - ); - } - } else { - if !exit_queue.nominators_leaving.remove(&nominator) { - log::warn!( - "Nominators set removal failed, - NominatorState had inconsistency!", - ); - } - if let Some(state) = >::get(&nominator) { - for bond in state.nominations.0 { - if let Err(error) = Self::nominator_leaves_collator( - nominator.clone(), - bond.owner.clone(), - ) { - log::warn!( - "Nominator leaves collator failed with error: {:?}", - error - ); - } - } - >::remove(&nominator); - Self::deposit_event(Event::NominatorLeft(nominator, state.total)); - } else { - log::warn!( - "Nominator State Not Found During Exit for Nominator {:?}", - nominator - ); - } - } - None - } - }) - .collect::, RoundIndex)>>(); - exit_queue.nominator_schedule = remaining_exits; - >::put(exit_queue); } + /// Compute the top `TotalSelected` candidates in the CandidatePool and return /// a vec of their AccountIds (in the order of selection) pub fn compute_top_candidates() -> Vec { let mut candidates = >::get().0; // order candidates by stake (least to greatest so requires `rev()`) - candidates.sort_unstable_by(|a, b| a.amount.partial_cmp(&b.amount).unwrap()); + candidates.sort_by(|a, b| a.amount.partial_cmp(&b.amount).unwrap()); let top_n = >::get() as usize; // choose the top TotalSelected qualified candidates, ordered by stake let mut collators = candidates @@ -1937,27 +3244,33 @@ pub mod pallet { collators } /// Best as in most cumulatively supported in terms of stake - /// Returns [collator_count, nomination_count, total staked] - fn select_top_candidates(next: RoundIndex) -> (u32, u32, BalanceOf) { - let (mut collator_count, mut nomination_count, mut total) = + /// Returns [collator_count, delegation_count, total staked] + fn select_top_candidates(now: RoundIndex) -> (u32, u32, BalanceOf) { + let (mut collator_count, mut delegation_count, mut total) = (0u32, 0u32, BalanceOf::::zero()); // choose the top TotalSelected qualified candidates, ordered by stake let collators = Self::compute_top_candidates(); // snapshot exposure for round for weighting reward distribution for account in collators.iter() { - let state = >::get(&account) + let state = >::get(account) + .expect("all members of CandidateQ must be candidates"); + let top_delegations = >::get(account) .expect("all members of CandidateQ must be candidates"); collator_count += 1u32; - nomination_count += state.nominators.0.len() as u32; - let amount = state.total_counted; - total += amount; - let exposure: CollatorSnapshot> = state.into(); - >::insert(next, account, exposure); - Self::deposit_event(Event::CollatorChosen(next, account.clone(), amount)); + delegation_count += state.delegation_count; + total += state.total_counted; + let snapshot_total = state.total_counted; + let snapshot = CollatorSnapshot { + bond: state.bond, + delegations: top_delegations.delegations, + total: state.total_counted, + }; + >::insert(now, account, snapshot); + Self::deposit_event(Event::CollatorChosen(now, account.clone(), snapshot_total)); } // insert canonical collator set >::put(collators); - (collator_count, nomination_count, total) + (collator_count, delegation_count, total) } } diff --git a/pallets/parachain-staking/src/migrations.rs b/pallets/parachain-staking/src/migrations.rs new file mode 100644 index 00000000..836f4c20 --- /dev/null +++ b/pallets/parachain-staking/src/migrations.rs @@ -0,0 +1,497 @@ +// Copyright 2019-2022 PureStake Inc. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +//! # Migrations +use crate::{ + pallet::Total, BalanceOf, Bond, BottomDelegations, CandidateInfo, CandidateMetadata, + CandidateState, CapacityStatus, CollatorCandidate, Config, Delegations, DelegatorState, + Event, Pallet, Points, Round, Staked, TopDelegations, +}; +#[cfg(feature = "try-runtime")] +use crate::{Collator2, Delegator, Nominator2}; +#[cfg(feature = "try-runtime")] +use frame_support::traits::OnRuntimeUpgradeHelpersExt; +use frame_support::Twox64Concat; +extern crate alloc; +#[cfg(feature = "try-runtime")] +use alloc::format; +use frame_support::{ + migration::{remove_storage_prefix, storage_key_iter}, + pallet_prelude::PhantomData, + traits::{Get, OnRuntimeUpgrade, ReservableCurrency}, + weights::Weight, +}; +use sp_runtime::traits::Zero; +use sp_std::{convert::TryInto, vec::Vec}; + +/// Migration to split CandidateState and minimize unnecessary storage reads +/// for PoV optimization +/// This assumes Config::MaxTopDelegationsPerCandidate == OldConfig::MaxDelegatorsPerCandidate +pub struct SplitCandidateStateToDecreasePoV(PhantomData); +impl OnRuntimeUpgrade for SplitCandidateStateToDecreasePoV { + fn on_runtime_upgrade() -> Weight { + let pallet_prefix: &[u8] = b"ParachainStaking"; + let storage_item_prefix: &[u8] = b"CandidateState"; + // Read all the data into memory. + // https://crates.parity.io/frame_support/storage/migration/fn.storage_key_iter.html + let stored_data: Vec<_> = storage_key_iter::< + T::AccountId, + CollatorCandidate>, + Twox64Concat, + >(pallet_prefix, storage_item_prefix) + .collect(); + let migrated_count: Weight = stored_data + .len() + .try_into() + .expect("There are between 0 and 2**64 mappings stored."); + // Now remove the old storage + // https://crates.parity.io/frame_support/storage/migration/fn.remove_storage_prefix.html + remove_storage_prefix(pallet_prefix, storage_item_prefix, &[]); + // Assert that old storage is empty + assert!(storage_key_iter::< + T::AccountId, + CollatorCandidate>, + Twox64Concat, + >(pallet_prefix, storage_item_prefix) + .next() + .is_none()); + for (account, state) in stored_data { + // all delegations are stored greatest to least post migration + // but bottom delegations were least to greatest pre migration + let new_bottom_delegations: Vec>> = + if state.bottom_delegations.len() + > T::MaxBottomDelegationsPerCandidate::get() as usize + { + // if actual length > max bottom delegations, revoke the bottom actual - max + let rest = state.bottom_delegations.len() + - T::MaxBottomDelegationsPerCandidate::get() as usize; + let mut total_less = BalanceOf::::zero(); + state.bottom_delegations.iter().take(rest).for_each( + |Bond { owner, amount }| { + total_less += *amount; + // update delegator state + // unreserve kicked bottom + T::Currency::unreserve(&owner, *amount); + let mut delegator_state = >::get(&owner) + .expect("Delegation existence => DelegatorState existence"); + let leaving = delegator_state.delegations.0.len() == 1usize; + delegator_state.rm_delegation(&account); + Pallet::::deposit_event(Event::DelegationKicked( + owner.clone(), + account.clone(), + *amount, + )); + if leaving { + >::remove(&owner); + Pallet::::deposit_event(Event::DelegatorLeft( + owner.clone(), + *amount, + )); + } else { + >::insert(&owner, delegator_state); + } + }, + ); + let new_total = >::get() - total_less; + >::put(new_total); + state + .bottom_delegations + .into_iter() + .rev() + .take(T::MaxBottomDelegationsPerCandidate::get() as usize) + .collect() + } else { + state.bottom_delegations.into_iter().rev().collect() + }; + let lowest_top_delegation_amount = if state.top_delegations.is_empty() { + BalanceOf::::zero() + } else { + state.top_delegations[state.top_delegations.len() - 1].amount + }; + let highest_bottom_delegation_amount = if new_bottom_delegations.is_empty() { + BalanceOf::::zero() + } else { + new_bottom_delegations[0].amount + }; + // start here, + let lowest_bottom_delegation_amount = if new_bottom_delegations.is_empty() { + BalanceOf::::zero() + } else { + new_bottom_delegations[new_bottom_delegations.len() - 1].amount + }; + let top_capacity = match &state.top_delegations { + x if x.len() as u32 >= T::MaxTopDelegationsPerCandidate::get() => { + CapacityStatus::Full + } + x if x.is_empty() => CapacityStatus::Empty, + _ => CapacityStatus::Partial, + }; + let bottom_capacity = match &new_bottom_delegations { + x if x.len() as u32 >= T::MaxBottomDelegationsPerCandidate::get() => { + CapacityStatus::Full + } + x if x.is_empty() => CapacityStatus::Empty, + _ => CapacityStatus::Partial, + }; + let metadata = CandidateMetadata { + bond: state.bond, + delegation_count: state.top_delegations.len() as u32 + + new_bottom_delegations.len() as u32, + total_counted: state.total_counted, + lowest_top_delegation_amount, + highest_bottom_delegation_amount, + lowest_bottom_delegation_amount, + top_capacity, + bottom_capacity, + request: state.request, + status: state.state, + }; + >::insert(&account, metadata); + let top_delegations = Delegations { + total: state.total_counted - state.bond, + delegations: state.top_delegations, + }; + >::insert(&account, top_delegations); + let bottom_delegations = Delegations { + total: new_bottom_delegations + .iter() + .fold(BalanceOf::::zero(), |acc, b| acc + b.amount), + delegations: new_bottom_delegations, + }; + >::insert(&account, bottom_delegations); + } + let weight = T::DbWeight::get(); + migrated_count.saturating_mul(3 * weight.write + weight.read) + } + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result<(), &'static str> { + // get delegation count for all candidates to check consistency + for (account, state) in >::iter() { + // insert top + bottom into some temp map? + let total_delegation_count = + state.top_delegations.len() as u32 + state.bottom_delegations.len() as u32; + Self::set_temp_storage( + total_delegation_count, + &format!("Candidate{}DelegationCount", account)[..], + ); + } + Ok(()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade() -> Result<(), &'static str> { + // check that top + bottom are the same as the expected (stored in temp) + for (account, state) in >::iter() { + let expected_count: u32 = + Self::get_temp_storage(&format!("Candidate{}DelegationCount", account)[..]) + .expect("qed"); + let actual_count = state.delegation_count; + assert_eq!(expected_count, actual_count); + } + Ok(()) + } +} + +/// Migration to properly increase maximum delegations per collator +/// The logic may be used to recompute the top and bottom delegations whenever +/// MaxTopDelegationsPerCandidate changes (works for if decreases as well) +pub struct IncreaseMaxDelegationsPerCandidate(PhantomData); +impl OnRuntimeUpgrade for IncreaseMaxDelegationsPerCandidate { + fn on_runtime_upgrade() -> Weight { + let (mut reads, mut writes) = (0u64, 0u64); + for (account, state) in >::iter() { + reads += 1u64; + // 1. collect all delegations into single vec and order them + let mut all_delegations = state.top_delegations.clone(); + let mut starting_bottom_delegations = state.bottom_delegations.clone(); + all_delegations.append(&mut starting_bottom_delegations); + // sort all delegations from greatest to least + all_delegations.sort_unstable_by(|a, b| b.amount.cmp(&a.amount)); + let top_n = T::MaxTopDelegationsPerCandidate::get() as usize; + // 2. split them into top and bottom using the T::MaxNominatorsPerCollator + let top_delegations: Vec>> = + all_delegations.iter().take(top_n).cloned().collect(); + let bottom_delegations = if all_delegations.len() > top_n { + let rest = all_delegations.len() - top_n; + let bottom: Vec>> = + all_delegations.iter().rev().take(rest).cloned().collect(); + bottom + } else { + // empty, all nominations are in top + Vec::new() + }; + let (mut total_counted, mut total_backing): (BalanceOf, BalanceOf) = + (state.bond.into(), state.bond.into()); + for Bond { amount, .. } in &top_delegations { + total_counted += *amount; + total_backing += *amount; + } + for Bond { amount, .. } in &bottom_delegations { + total_backing += *amount; + } + // update candidate pool with new total counted if it changed + if state.total_counted != total_counted && state.is_active() { + reads += 1u64; + writes += 1u64; + >::update_active(account.clone(), total_counted); + } + >::insert( + account, + CollatorCandidate { + top_delegations, + bottom_delegations, + total_counted, + total_backing, + ..state + }, + ); + writes += 1u64; + } + let weight = T::DbWeight::get(); + // 20% of the max block weight as safety margin for computation + weight.reads(reads) + weight.writes(writes) + 100_000_000_000 + } + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result<(), &'static str> { + // get delegation count for all candidates to check consistency + for (account, state) in >::iter() { + // insert top + bottom into some temp map? + let total_delegation_count = + state.top_delegations.len() as u32 + state.bottom_delegations.len() as u32; + Self::set_temp_storage( + total_delegation_count, + &format!("Candidate{:?}DelegationCount", account)[..], + ); + } + Ok(()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade() -> Result<(), &'static str> { + // check that top + bottom are the same as the expected (stored in temp) + for (account, state) in >::iter() { + let expected_count: u32 = + Self::get_temp_storage(&format!("Candidate{:?}DelegationCount", account)[..]) + .expect("qed"); + let actual_count = + state.top_delegations.len() as u32 + state.bottom_delegations.len() as u32; + assert_eq!(expected_count, actual_count); + } + Ok(()) + } +} + +/// Migration to replace the automatic ExitQueue with a manual exits API. +/// This migration is idempotent so it can be run more than once without any risk. +// pub struct RemoveExitQueue(PhantomData); +// impl OnRuntimeUpgrade for RemoveExitQueue { +// fn on_runtime_upgrade() -> Weight { +// log::info!(target: "RemoveExitQueue", "running migration to remove staking exit queue"); +// let exit_queue = >::take(); +// let (mut reads, mut writes) = (1u64, 0u64); +// let mut delegator_exits: BTreeMap = BTreeMap::new(); +// let mut delegation_revocations: BTreeMap = +// BTreeMap::new(); +// // Track scheduled delegator exits and revocations before migrating state +// // Candidates already track exit info locally so no tracking is necessary +// for (delegator, is_revocation, when) in exit_queue.nominator_schedule { +// if let Some(revoking_candidate) = is_revocation { +// delegation_revocations.insert(delegator, (revoking_candidate, when)); +// } else { +// delegator_exits.insert(delegator, when); +// } +// } +// // execute candidate migration +// for (candidate_id, collator_state) in >::drain() { +// let candidate_state: CollatorCandidate> = +// collator_state.into(); +// >::insert(candidate_id, candidate_state); +// reads += 1u64; +// writes += 1u64; +// } +// // execute delegator migration +// for (delegator_id, nominator_state) in >::drain() { +// let mut delegator_state = +// migrate_nominator_to_delegator_state::(delegator_id.clone(), nominator_state); +// // add exit if it exists +// if let Some(when) = delegator_exits.get(&delegator_id) { +// delegator_state.set_leaving(*when); +// } +// // add revocation if exists +// if let Some((candidate, when)) = delegation_revocations.get(&delegator_id) { +// delegator_state.hotfix_set_revoke::(candidate.clone(), *when); +// } +// >::insert(delegator_id, delegator_state); +// reads += 1u64; +// writes += 1u64; +// } +// let db_weight = T::DbWeight::get(); +// if reads > 1u64 { +// // 50% of the max block weight as safety margin for computation +// db_weight.reads(reads) + db_weight.writes(writes) + 250_000_000_000 +// } else { +// // migration was already executed before +// db_weight.reads(reads) +// } +// } + +// #[cfg(feature = "try-runtime")] +// fn pre_upgrade() -> Result<(), &'static str> { +// use frame_support::storage::migration::storage_iter; + +// let pallet_prefix: &[u8] = b"ParachainStaking"; +// let collator_state_prefix: &[u8] = b"CollatorState2"; +// let nominator_state_prefix: &[u8] = b"NominatorState2"; + +// // Assert new storage is empty +// assert!(CandidateState::::iter().next().is_none()); +// assert!(DelegatorState::::iter().next().is_none()); + +// // Check number of old collator candidates, and set it aside in temp storage +// let old_collator_count = storage_iter::>>( +// pallet_prefix, +// collator_state_prefix, +// ) +// .count() as u64; +// Self::set_temp_storage(old_collator_count, "old_collator_count"); + +// // Read first old candidate from old storage and set it aside in temp storage +// if old_collator_count > 0 { +// let example_collator = storage_key_iter::< +// T::AccountId, +// Collator2>, +// Twox64Concat, +// >(pallet_prefix, collator_state_prefix) +// .next() +// .expect("We already confirmed that there was at least one item stored"); + +// Self::set_temp_storage(example_collator, "example_collator"); +// } + +// // Check number of new delegators, and set it aside in temp storage +// let old_nominator_count = storage_iter::>>( +// pallet_prefix, +// nominator_state_prefix, +// ) +// .count() as u64; +// Self::set_temp_storage(old_nominator_count, "old_nominator_count"); + +// // Read first new delegator from old storage and set it aside in temp storage +// if old_nominator_count > 0 { +// let example_nominator = storage_key_iter::< +// T::AccountId, +// Nominator2>, +// Twox64Concat, +// >(pallet_prefix, nominator_state_prefix) +// .next() +// .expect("We already confirmed that there was at least one item stored"); + +// Self::set_temp_storage(example_nominator, "example_nominator"); +// } +// Ok(()) +// } + +// #[cfg(feature = "try-runtime")] +// fn post_upgrade() -> Result<(), &'static str> { +// // Check number of candidates matches what was set aside in pre_upgrade +// let old_candidate_count: u64 = Self::get_temp_storage("old_collator_count") +// .expect("We stored the old collator candidate count so it should be there"); +// let new_candidate_count = CandidateState::::iter().count() as u64; +// assert_eq!(old_candidate_count, new_candidate_count); + +// // Check that our example candidate is converted correctly +// if new_candidate_count > 0 { +// let (account, original_collator_state): ( +// T::AccountId, +// Collator2>, +// ) = Self::get_temp_storage("example_collator").expect("qed"); +// let new_candidate_state = CandidateState::::get(account).expect("qed"); +// let old_candidate_converted: CollatorCandidate> = +// original_collator_state.into(); +// assert_eq!(new_candidate_state, old_candidate_converted); +// } + +// // Check number of delegators matches what was set aside in pre_upgrade +// let old_nominator_count: u64 = Self::get_temp_storage("old_nominator_count") +// .expect("We stored the old nominator count so it should be there"); +// let new_delegator_count = DelegatorState::::iter().count() as u64; +// assert_eq!(old_nominator_count, new_delegator_count); + +// // Check that our example delegator is converted correctly +// if new_delegator_count > 0 { +// let (account, original_delegator_state): ( +// T::AccountId, +// Nominator2>, +// ) = Self::get_temp_storage("example_nominator").expect("qed"); +// let new_delegator_state = DelegatorState::::get(&account).expect("qed"); +// let old_delegator_converted: Delegator> = +// migrate_nominator_to_delegator_state::(account, original_delegator_state); +// assert_eq!(old_delegator_converted, new_delegator_state); +// } +// Ok(()) +// } +// } + +/// Migration to purge staking storage bloat for `Points` and `AtStake` storage items +pub struct PurgeStaleStorage(PhantomData); +impl OnRuntimeUpgrade for PurgeStaleStorage { + fn on_runtime_upgrade() -> Weight { + log::info!(target: "PurgeStaleStorage", "running migration to remove storage bloat"); + let current_round = >::get().current; + let payment_delay = T::RewardPaymentDelay::get(); + let db_weight = T::DbWeight::get(); + let (reads, mut writes) = (3u64, 0u64); + if current_round <= payment_delay { + // early enough so no storage bloat exists yet + // (only relevant for chains <= payment_delay rounds old) + return db_weight.reads(reads); + } + // already paid out at the beginning of current round + let most_recent_round_to_kill = current_round - payment_delay; + for i in 1..=most_recent_round_to_kill { + writes += 2u64; + >::remove(i); + >::remove(i); + } + // 5% of the max block weight as safety margin for computation + db_weight.reads(reads) + db_weight.writes(writes) + 25_000_000_000 + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result<(), &'static str> { + // trivial migration + Ok(()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade() -> Result<(), &'static str> { + // expect only the storage items for the last 2 rounds to be stored + let staked_count = Staked::::iter().count() as u32; + let points_count = Points::::iter().count() as u32; + let delay = T::RewardPaymentDelay::get(); + assert_eq!( + staked_count, delay, + "Expected {} for `Staked` count, Found: {}", + delay, staked_count + ); + assert_eq!( + points_count, delay, + "Expected {} for `Points` count, Found: {}", + delay, staked_count + ); + Ok(()) + } +} diff --git a/pallets/parachain-staking/src/mock.rs b/pallets/parachain-staking/src/mock.rs index fc436c54..17e731e5 100644 --- a/pallets/parachain-staking/src/mock.rs +++ b/pallets/parachain-staking/src/mock.rs @@ -1,4 +1,4 @@ -// Copyright 2019-2021 PureStake Inc. +// Copyright 2019-2022 PureStake Inc. // This file is part of Moonbeam. // Moonbeam is free software: you can redistribute it and/or modify @@ -15,7 +15,7 @@ // along with Moonbeam. If not, see . //! Test utilities -use crate as stake; +use crate as parachain_staking; use crate::{pallet, AwardedPts, Config, InflationInfo, Points, Range}; use frame_support::{ construct_runtime, parameter_types, @@ -46,7 +46,7 @@ construct_runtime!( { System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - Stake: stake::{Pallet, Call, Storage, Config, Event}, + ParachainStaking: parachain_staking::{Pallet, Call, Storage, Config, Event}, } ); @@ -55,7 +55,7 @@ parameter_types! { pub const MaximumBlockWeight: Weight = 1024; pub const MaximumBlockLength: u32 = 2 * 1024; pub const AvailableBlockRatio: Perbill = Perbill::one(); - pub const SS58Prefix: u8 = 105; + pub const SS58Prefix: u8 = 42; } impl frame_system::Config for Test { type BaseCallFilter = Everything; @@ -81,6 +81,7 @@ impl frame_system::Config for Test { type BlockLength = (); type SS58Prefix = SS58Prefix; type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; } parameter_types! { pub const ExistentialDeposit: u128 = 1; @@ -100,17 +101,20 @@ parameter_types! { pub const MinBlocksPerRound: u32 = 3; pub const DefaultBlocksPerRound: u32 = 5; pub const LeaveCandidatesDelay: u32 = 2; - pub const LeaveNominatorsDelay: u32 = 2; - pub const RevokeNominationDelay: u32 = 2; + pub const CandidateBondLessDelay: u32 = 2; + pub const LeaveDelegatorsDelay: u32 = 2; + pub const RevokeDelegationDelay: u32 = 2; + pub const DelegationBondLessDelay: u32 = 2; pub const RewardPaymentDelay: u32 = 2; pub const MinSelectedCandidates: u32 = 5; - pub const MaxNominatorsPerCollator: u32 = 4; - pub const MaxCollatorsPerNominator: u32 = 4; + pub const MaxTopDelegationsPerCandidate: u32 = 4; + pub const MaxBottomDelegationsPerCandidate: u32 = 4; + pub const MaxDelegationsPerDelegator: u32 = 4; pub const DefaultCollatorCommission: Perbill = Perbill::from_percent(20); pub const DefaultParachainBondReservePercent: Percent = Percent::from_percent(30); pub const MinCollatorStk: u128 = 10; - pub const MinNominatorStk: u128 = 5; - pub const MinNomination: u128 = 3; + pub const MinDelegatorStk: u128 = 5; + pub const MinDelegation: u128 = 3; } impl Config for Test { type Event = Event; @@ -119,18 +123,21 @@ impl Config for Test { type MinBlocksPerRound = MinBlocksPerRound; type DefaultBlocksPerRound = DefaultBlocksPerRound; type LeaveCandidatesDelay = LeaveCandidatesDelay; - type LeaveNominatorsDelay = LeaveNominatorsDelay; - type RevokeNominationDelay = RevokeNominationDelay; + type CandidateBondLessDelay = CandidateBondLessDelay; + type LeaveDelegatorsDelay = LeaveDelegatorsDelay; + type RevokeDelegationDelay = RevokeDelegationDelay; + type DelegationBondLessDelay = DelegationBondLessDelay; type RewardPaymentDelay = RewardPaymentDelay; type MinSelectedCandidates = MinSelectedCandidates; - type MaxNominatorsPerCollator = MaxNominatorsPerCollator; - type MaxCollatorsPerNominator = MaxCollatorsPerNominator; + type MaxTopDelegationsPerCandidate = MaxTopDelegationsPerCandidate; + type MaxBottomDelegationsPerCandidate = MaxBottomDelegationsPerCandidate; + type MaxDelegationsPerDelegator = MaxDelegationsPerDelegator; type DefaultCollatorCommission = DefaultCollatorCommission; type DefaultParachainBondReservePercent = DefaultParachainBondReservePercent; type MinCollatorStk = MinCollatorStk; - type MinCollatorCandidateStk = MinCollatorStk; - type MinNominatorStk = MinNominatorStk; - type MinNomination = MinNomination; + type MinCandidateStk = MinCollatorStk; + type MinDelegatorStk = MinDelegatorStk; + type MinDelegation = MinDelegation; type WeightInfo = (); } @@ -139,8 +146,8 @@ pub(crate) struct ExtBuilder { balances: Vec<(AccountId, Balance)>, // [collator, amount] collators: Vec<(AccountId, Balance)>, - // [nominator, collator, nomination_amount] - nominations: Vec<(AccountId, AccountId, Balance)>, + // [delegator, collator, delegation_amount] + delegations: Vec<(AccountId, AccountId, Balance)>, // inflation config inflation: InflationInfo, } @@ -149,7 +156,7 @@ impl Default for ExtBuilder { fn default() -> ExtBuilder { ExtBuilder { balances: vec![], - nominations: vec![], + delegations: vec![], collators: vec![], inflation: InflationInfo { expect: Range { @@ -185,11 +192,11 @@ impl ExtBuilder { self } - pub(crate) fn with_nominations( + pub(crate) fn with_delegations( mut self, - nominations: Vec<(AccountId, AccountId, Balance)>, + delegations: Vec<(AccountId, AccountId, Balance)>, ) -> Self { - self.nominations = nominations; + self.delegations = delegations; self } @@ -209,9 +216,9 @@ impl ExtBuilder { } .assimilate_storage(&mut t) .expect("Pallet balances storage can be assimilated"); - stake::GenesisConfig:: { + parachain_staking::GenesisConfig:: { candidates: self.collators, - nominations: self.nominations, + delegations: self.delegations, inflation_config: self.inflation, } .assimilate_storage(&mut t) @@ -223,16 +230,42 @@ impl ExtBuilder { } } -pub(crate) fn roll_to(n: u64) { - while System::block_number() < n { - Stake::on_finalize(System::block_number()); - Balances::on_finalize(System::block_number()); - System::on_finalize(System::block_number()); - System::set_block_number(System::block_number() + 1); - System::on_initialize(System::block_number()); - Balances::on_initialize(System::block_number()); - Stake::on_initialize(System::block_number()); +/// Rolls forward one block. Returns the new block number. +pub(crate) fn roll_one_block() -> u64 { + ParachainStaking::on_finalize(System::block_number()); + Balances::on_finalize(System::block_number()); + System::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + System::on_initialize(System::block_number()); + Balances::on_initialize(System::block_number()); + ParachainStaking::on_initialize(System::block_number()); + System::block_number() +} + +/// Rolls to the desired block. Returns the number of blocks played. +pub(crate) fn roll_to(n: u64) -> u64 { + let mut num_blocks = 0; + let mut block = System::block_number(); + while block < n { + block = roll_one_block(); + num_blocks += 1; } + num_blocks +} + +/// Rolls block-by-block to the beginning of the specified round. +/// This will complete the block in which the round change occurs. +/// Returns the number of blocks played. +pub(crate) fn roll_to_round_begin(round: u64) -> u64 { + let block = (round - 1) * DefaultBlocksPerRound::get() as u64; + roll_to(block) +} + +/// Rolls block-by-block to the end of the specified round. +/// The block following will be the one in which the specified round change occurs. +pub(crate) fn roll_to_round_end(round: u64) -> u64 { + let block = round * DefaultBlocksPerRound::get() as u64 - 1; + roll_to(block) } pub(crate) fn last_event() -> Event { @@ -244,7 +277,7 @@ pub(crate) fn events() -> Vec> { .into_iter() .map(|r| r.event) .filter_map(|e| { - if let Event::Stake(inner) = e { + if let Event::ParachainStaking(inner) = e { Some(inner) } else { None @@ -253,6 +286,102 @@ pub(crate) fn events() -> Vec> { .collect::>() } +/// Assert input equal to the last event emitted +#[macro_export] +macro_rules! assert_last_event { + ($event:expr) => { + match &$event { + e => assert_eq!(*e, crate::mock::last_event()), + } + }; +} + +/// Compares the system events with passed in events +/// Prints highlighted diff iff assert_eq fails +#[macro_export] +macro_rules! assert_eq_events { + ($events:expr) => { + match &$events { + e => similar_asserts::assert_eq!(*e, crate::mock::events()), + } + }; +} + +/// Compares the last N system events with passed in events, where N is the length of events passed +/// in. +/// +/// Prints highlighted diff iff assert_eq fails. +/// The last events from frame_system will be taken in order to match the number passed to this +/// macro. If there are insufficient events from frame_system, they will still be compared; the +/// output may or may not be helpful. +/// +/// Examples: +/// If frame_system has events [A, B, C, D, E] and events [C, D, E] are passed in, the result would +/// be a successful match ([C, D, E] == [C, D, E]). +/// +/// If frame_system has events [A, B, C, D] and events [B, C] are passed in, the result would be an +/// error and a hopefully-useful diff will be printed between [C, D] and [B, C]. +/// +/// Note that events are filtered to only match parachain-staking (see events()). +#[macro_export] +macro_rules! assert_eq_last_events { + ($events:expr) => { + assert_tail_eq!($events, crate::mock::events()); + }; +} + +/// Assert that one array is equal to the tail of the other. A more generic and testable version of +/// assert_eq_last_events. +#[macro_export] +macro_rules! assert_tail_eq { + ($tail:expr, $arr:expr) => { + if $tail.len() != 0 { + // 0-length always passes + + if $tail.len() > $arr.len() { + similar_asserts::assert_eq!($tail, $arr); // will fail + } + + let len_diff = $arr.len() - $tail.len(); + similar_asserts::assert_eq!($tail, $arr[len_diff..]); + } + }; +} + +/// Panics if an event is not found in the system log of events +#[macro_export] +macro_rules! assert_event_emitted { + ($event:expr) => { + match &$event { + e => { + assert!( + crate::mock::events().iter().find(|x| *x == e).is_some(), + "Event {:?} was not found in events: \n {:?}", + e, + crate::mock::events() + ); + } + } + }; +} + +/// Panics if an event is found in the system log of events +#[macro_export] +macro_rules! assert_event_not_emitted { + ($event:expr) => { + match &$event { + e => { + assert!( + crate::mock::events().iter().find(|x| *x == e).is_none(), + "Event {:?} was found in events: \n {:?}", + e, + crate::mock::events() + ); + } + } + }; +} + // Same storage changes as EventHandler::note_author impl pub(crate) fn set_author(round: u32, acc: u64, pts: u32) { >::mutate(round, |p| *p += pts); @@ -274,26 +403,26 @@ fn geneses() { (9, 4), ]) .with_candidates(vec![(1, 500), (2, 200)]) - .with_nominations(vec![(3, 1, 100), (4, 1, 100), (5, 2, 100), (6, 2, 100)]) + .with_delegations(vec![(3, 1, 100), (4, 1, 100), (5, 2, 100), (6, 2, 100)]) .build() .execute_with(|| { assert!(System::events().is_empty()); // collators assert_eq!(Balances::reserved_balance(&1), 500); assert_eq!(Balances::free_balance(&1), 500); - assert!(Stake::is_candidate(&1)); + assert!(ParachainStaking::is_candidate(&1)); assert_eq!(Balances::reserved_balance(&2), 200); assert_eq!(Balances::free_balance(&2), 100); - assert!(Stake::is_candidate(&2)); - // nominators + assert!(ParachainStaking::is_candidate(&2)); + // delegators for x in 3..7 { - assert!(Stake::is_nominator(&x)); + assert!(ParachainStaking::is_delegator(&x)); assert_eq!(Balances::free_balance(&x), 0); assert_eq!(Balances::reserved_balance(&x), 100); } // uninvolved for x in 7..10 { - assert!(!Stake::is_nominator(&x)); + assert!(!ParachainStaking::is_delegator(&x)); } assert_eq!(Balances::free_balance(&7), 100); assert_eq!(Balances::reserved_balance(&7), 0); @@ -316,7 +445,7 @@ fn geneses() { (10, 100), ]) .with_candidates(vec![(1, 20), (2, 20), (3, 20), (4, 20), (5, 10)]) - .with_nominations(vec![ + .with_delegations(vec![ (6, 1, 10), (7, 1, 10), (8, 2, 10), @@ -328,18 +457,96 @@ fn geneses() { assert!(System::events().is_empty()); // collators for x in 1..5 { - assert!(Stake::is_candidate(&x)); + assert!(ParachainStaking::is_candidate(&x)); assert_eq!(Balances::free_balance(&x), 80); assert_eq!(Balances::reserved_balance(&x), 20); } - assert!(Stake::is_candidate(&5)); + assert!(ParachainStaking::is_candidate(&5)); assert_eq!(Balances::free_balance(&5), 90); assert_eq!(Balances::reserved_balance(&5), 10); - // nominators + // delegators for x in 6..11 { - assert!(Stake::is_nominator(&x)); + assert!(ParachainStaking::is_delegator(&x)); assert_eq!(Balances::free_balance(&x), 90); assert_eq!(Balances::reserved_balance(&x), 10); } }); } + +#[test] +fn roll_to_round_begin_works() { + ExtBuilder::default().build().execute_with(|| { + // these tests assume blocks-per-round of 5, as established by DefaultBlocksPerRound + assert_eq!(System::block_number(), 1); // we start on block 1 + + let num_blocks = roll_to_round_begin(1); + assert_eq!(System::block_number(), 1); // no-op, we're already on this round + assert_eq!(num_blocks, 0); + + let num_blocks = roll_to_round_begin(2); + assert_eq!(System::block_number(), 5); + assert_eq!(num_blocks, 4); + + let num_blocks = roll_to_round_begin(3); + assert_eq!(System::block_number(), 10); + assert_eq!(num_blocks, 5); + }); +} + +#[test] +fn roll_to_round_end_works() { + ExtBuilder::default().build().execute_with(|| { + // these tests assume blocks-per-round of 5, as established by DefaultBlocksPerRound + assert_eq!(System::block_number(), 1); // we start on block 1 + + let num_blocks = roll_to_round_end(1); + assert_eq!(System::block_number(), 4); + assert_eq!(num_blocks, 3); + + let num_blocks = roll_to_round_end(2); + assert_eq!(System::block_number(), 9); + assert_eq!(num_blocks, 5); + + let num_blocks = roll_to_round_end(3); + assert_eq!(System::block_number(), 14); + assert_eq!(num_blocks, 5); + }); +} + +#[test] +fn assert_tail_eq_works() { + assert_tail_eq!(vec![1, 2], vec![0, 1, 2]); + + assert_tail_eq!(vec![1], vec![1]); + + assert_tail_eq!( + vec![0u32; 0], // 0 length array + vec![0u32; 1] // 1-length array + ); + + assert_tail_eq!(vec![0u32, 0], vec![0u32, 0]); +} + +#[test] +#[should_panic] +fn assert_tail_eq_panics_on_non_equal_tail() { + assert_tail_eq!(vec![2, 2], vec![0, 1, 2]); +} + +#[test] +#[should_panic] +fn assert_tail_eq_panics_on_empty_arr() { + assert_tail_eq!(vec![2, 2], vec![0u32; 0]); +} + +#[test] +#[should_panic] +fn assert_tail_eq_panics_on_longer_tail() { + assert_tail_eq!(vec![1, 2, 3], vec![1, 2]); +} + +#[test] +#[should_panic] +fn assert_tail_eq_panics_on_unequal_elements_same_length_array() { + assert_tail_eq!(vec![1, 2, 3], vec![0, 1, 2]); +} diff --git a/pallets/parachain-staking/src/set.rs b/pallets/parachain-staking/src/set.rs index 860d6d62..d4775eba 100644 --- a/pallets/parachain-staking/src/set.rs +++ b/pallets/parachain-staking/src/set.rs @@ -1,4 +1,4 @@ -// Copyright 2019-2021 PureStake Inc. +// Copyright 2019-2022 PureStake Inc. // This file is part of Moonbeam. // Moonbeam is free software: you can redistribute it and/or modify @@ -62,7 +62,7 @@ impl OrderedSet { /// Remove an element. /// Return true if removal happened. pub fn remove(&mut self, value: &T) -> bool { - match self.0.binary_search(&value) { + match self.0.binary_search(value) { Ok(loc) => { self.0.remove(loc); true @@ -73,7 +73,7 @@ impl OrderedSet { /// Return if the set contains `value` pub fn contains(&self, value: &T) -> bool { - self.0.binary_search(&value).is_ok() + self.0.binary_search(value).is_ok() } /// Clear the set diff --git a/pallets/parachain-staking/src/tests.rs b/pallets/parachain-staking/src/tests.rs index 895a8ebf..1866d718 100644 --- a/pallets/parachain-staking/src/tests.rs +++ b/pallets/parachain-staking/src/tests.rs @@ -1,4 +1,4 @@ -// Copyright 2019-2021 PureStake Inc. +// Copyright 2019-2022 PureStake Inc. // This file is part of Moonbeam. // Moonbeam is free software: you can redistribute it and/or modify @@ -22,24 +22,20 @@ //! 3. Public (Collator, Nominator) //! 4. Miscellaneous Property-Based Tests use crate::mock::{ - events, last_event, roll_to, set_author, Balances, Event as MetaEvent, ExtBuilder, Origin, - Stake, Test, + roll_one_block, roll_to, roll_to_round_begin, roll_to_round_end, set_author, Balances, + Event as MetaEvent, ExtBuilder, Origin, ParachainStaking, Test, }; -use crate::{Bond, CollatorStatus, Error, Event, NominatorAdded, Range}; -use frame_support::{assert_noop, assert_ok}; +use crate::{ + assert_eq_events, assert_eq_last_events, assert_event_emitted, assert_event_not_emitted, + assert_last_event, assert_tail_eq, pallet::CapacityStatus, set::OrderedSet, BalanceOf, Bond, + BottomDelegations, CandidateInfo, CandidatePool, CandidateState, CollatorCandidate, + CollatorStatus, Config, DelegationChange, DelegationRequest, Delegator, DelegatorAdded, + DelegatorState, DelegatorStatus, Error, Event, PendingDelegationRequests, Range, + TopDelegations, Total, +}; +use frame_support::{assert_noop, assert_ok, traits::ReservableCurrency}; use sp_runtime::{traits::Zero, DispatchError, Perbill, Percent}; - -/// Prints the diff iff assert_eq fails, should only be used for debugging purposes -#[macro_export] -macro_rules! asserts_eq { - ($left:expr, $right:expr) => { - match (&$left, &$right) { - (left_val, right_val) => { - similar_asserts::assert_eq!(*left_val, *right_val); - } - } - }; -} +use sp_std::collections::btree_map::BTreeMap; // ~~ ROOT ~~ @@ -47,15 +43,18 @@ macro_rules! asserts_eq { fn invalid_root_origin_fails() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - Stake::set_total_selected(Origin::signed(45), 6u32), + ParachainStaking::set_total_selected(Origin::signed(45), 6u32), sp_runtime::DispatchError::BadOrigin ); assert_noop!( - Stake::set_collator_commission(Origin::signed(45), Perbill::from_percent(5)), + ParachainStaking::set_collator_commission( + Origin::signed(45), + Perbill::from_percent(5) + ), sp_runtime::DispatchError::BadOrigin ); assert_noop!( - Stake::set_blocks_per_round(Origin::signed(45), 3u32), + ParachainStaking::set_blocks_per_round(Origin::signed(45), 3u32), sp_runtime::DispatchError::BadOrigin ); }); @@ -66,20 +65,95 @@ fn invalid_root_origin_fails() { #[test] fn set_total_selected_event_emits_correctly() { ExtBuilder::default().build().execute_with(|| { - assert_ok!(Stake::set_total_selected(Origin::root(), 6u32)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::TotalSelectedSet(5u32, 6u32,)) + // before we can bump total_selected we must bump the blocks per round + assert_ok!(ParachainStaking::set_blocks_per_round(Origin::root(), 6u32)); + assert_ok!(ParachainStaking::set_total_selected(Origin::root(), 6u32)); + assert_last_event!(MetaEvent::ParachainStaking(Event::TotalSelectedSet( + 5u32, 6u32 + ))); + }); +} + +#[test] +fn set_total_selected_fails_if_above_blocks_per_round() { + ExtBuilder::default().build().execute_with(|| { + assert_eq!(ParachainStaking::round().length, 5); // test relies on this + assert_noop!( + ParachainStaking::set_total_selected(Origin::root(), 6u32), + Error::::RoundLengthMustBeAtLeastTotalSelectedCollators, + ); + }); +} + +#[test] +fn set_total_selected_passes_if_equal_to_blocks_per_round() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(ParachainStaking::set_blocks_per_round( + Origin::root(), + 10u32 + )); + assert_ok!(ParachainStaking::set_total_selected(Origin::root(), 10u32)); + }); +} + +#[test] +fn set_total_selected_passes_if_below_blocks_per_round() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(ParachainStaking::set_blocks_per_round( + Origin::root(), + 10u32 + )); + assert_ok!(ParachainStaking::set_total_selected(Origin::root(), 9u32)); + }); +} + +#[test] +fn set_blocks_per_round_fails_if_below_total_selected() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(ParachainStaking::set_blocks_per_round( + Origin::root(), + 20u32 + )); + assert_ok!(ParachainStaking::set_total_selected(Origin::root(), 15u32)); + assert_noop!( + ParachainStaking::set_blocks_per_round(Origin::root(), 14u32), + Error::::RoundLengthMustBeAtLeastTotalSelectedCollators, ); }); } +#[test] +fn set_blocks_per_round_passes_if_equal_to_total_selected() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(ParachainStaking::set_blocks_per_round( + Origin::root(), + 10u32 + )); + assert_ok!(ParachainStaking::set_total_selected(Origin::root(), 9u32)); + assert_ok!(ParachainStaking::set_blocks_per_round(Origin::root(), 9u32)); + }); +} + +#[test] +fn set_blocks_per_round_passes_if_above_total_selected() { + ExtBuilder::default().build().execute_with(|| { + assert_eq!(ParachainStaking::round().length, 5); // test relies on this + assert_ok!(ParachainStaking::set_blocks_per_round(Origin::root(), 6u32)); + }); +} + #[test] fn set_total_selected_storage_updates_correctly() { ExtBuilder::default().build().execute_with(|| { - assert_eq!(Stake::total_selected(), 5u32); - assert_ok!(Stake::set_total_selected(Origin::root(), 6u32)); - assert_eq!(Stake::total_selected(), 6u32); + // round length must be >= total_selected, so update that first + assert_ok!(ParachainStaking::set_blocks_per_round( + Origin::root(), + 10u32 + )); + + assert_eq!(ParachainStaking::total_selected(), 5u32); + assert_ok!(ParachainStaking::set_total_selected(Origin::root(), 6u32)); + assert_eq!(ParachainStaking::total_selected(), 6u32); }); } @@ -87,7 +161,7 @@ fn set_total_selected_storage_updates_correctly() { fn cannot_set_total_selected_to_current_total_selected() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - Stake::set_total_selected(Origin::root(), 5u32), + ParachainStaking::set_total_selected(Origin::root(), 5u32), Error::::NoWritingSameValue ); }); @@ -97,7 +171,7 @@ fn cannot_set_total_selected_to_current_total_selected() { fn cannot_set_total_selected_below_module_min() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - Stake::set_total_selected(Origin::root(), 4u32), + ParachainStaking::set_total_selected(Origin::root(), 4u32), Error::::CannotSetBelowMin ); }); @@ -108,29 +182,32 @@ fn cannot_set_total_selected_below_module_min() { #[test] fn set_collator_commission_event_emits_correctly() { ExtBuilder::default().build().execute_with(|| { - assert_ok!(Stake::set_collator_commission( + assert_ok!(ParachainStaking::set_collator_commission( Origin::root(), Perbill::from_percent(5) )); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::CollatorCommissionSet( - Perbill::from_percent(20), - Perbill::from_percent(5), - )) - ); + assert_last_event!(MetaEvent::ParachainStaking(Event::CollatorCommissionSet( + Perbill::from_percent(20), + Perbill::from_percent(5), + ))); }); } #[test] fn set_collator_commission_storage_updates_correctly() { ExtBuilder::default().build().execute_with(|| { - assert_eq!(Stake::collator_commission(), Perbill::from_percent(20)); - assert_ok!(Stake::set_collator_commission( + assert_eq!( + ParachainStaking::collator_commission(), + Perbill::from_percent(20) + ); + assert_ok!(ParachainStaking::set_collator_commission( Origin::root(), Perbill::from_percent(5) )); - assert_eq!(Stake::collator_commission(), Perbill::from_percent(5)); + assert_eq!( + ParachainStaking::collator_commission(), + Perbill::from_percent(5) + ); }); } @@ -138,7 +215,7 @@ fn set_collator_commission_storage_updates_correctly() { fn cannot_set_collator_commission_to_current_collator_commission() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - Stake::set_collator_commission(Origin::root(), Perbill::from_percent(20)), + ParachainStaking::set_collator_commission(Origin::root(), Perbill::from_percent(20)), Error::::NoWritingSameValue ); }); @@ -149,28 +226,25 @@ fn cannot_set_collator_commission_to_current_collator_commission() { #[test] fn set_blocks_per_round_event_emits_correctly() { ExtBuilder::default().build().execute_with(|| { - assert_ok!(Stake::set_blocks_per_round(Origin::root(), 3u32)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::BlocksPerRoundSet( - 1, - 0, - 5, - 3, - Perbill::from_parts(463), - Perbill::from_parts(463), - Perbill::from_parts(463) - )) - ); + assert_ok!(ParachainStaking::set_blocks_per_round(Origin::root(), 6u32)); + assert_last_event!(MetaEvent::ParachainStaking(Event::BlocksPerRoundSet( + 1, + 0, + 5, + 6, + Perbill::from_parts(926), + Perbill::from_parts(926), + Perbill::from_parts(926), + ))); }); } #[test] fn set_blocks_per_round_storage_updates_correctly() { ExtBuilder::default().build().execute_with(|| { - assert_eq!(Stake::round().length, 5); - assert_ok!(Stake::set_blocks_per_round(Origin::root(), 3u32)); - assert_eq!(Stake::round().length, 3); + assert_eq!(ParachainStaking::round().length, 5); + assert_ok!(ParachainStaking::set_blocks_per_round(Origin::root(), 6u32)); + assert_eq!(ParachainStaking::round().length, 6); }); } @@ -178,7 +252,7 @@ fn set_blocks_per_round_storage_updates_correctly() { fn cannot_set_blocks_per_round_below_module_min() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - Stake::set_blocks_per_round(Origin::root(), 2u32), + ParachainStaking::set_blocks_per_round(Origin::root(), 2u32), Error::::CannotSetBelowMin ); }); @@ -188,7 +262,7 @@ fn cannot_set_blocks_per_round_below_module_min() { fn cannot_set_blocks_per_round_to_current_blocks_per_round() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - Stake::set_blocks_per_round(Origin::root(), 5u32), + ParachainStaking::set_blocks_per_round(Origin::root(), 5u32), Error::::NoWritingSameValue ); }); @@ -201,12 +275,19 @@ fn round_immediately_jumps_if_current_duration_exceeds_new_blocks_per_round() { .with_candidates(vec![(1, 20)]) .build() .execute_with(|| { - // default round every 5 blocks - roll_to(8); - assert_eq!(last_event(), MetaEvent::Stake(Event::NewRound(5, 2, 1, 20))); - assert_ok!(Stake::set_blocks_per_round(Origin::root(), 3u32)); - roll_to(9); - assert_eq!(last_event(), MetaEvent::Stake(Event::NewRound(9, 3, 1, 20))); + // we can't lower the blocks per round because it must be above the number of collators, + // and we can't lower the number of collators because it must be above + // MinSelectedCandidates. so we first raise blocks per round, then lower it. + assert_ok!(ParachainStaking::set_blocks_per_round( + Origin::root(), + 10u32 + )); + + roll_to(17); + assert_last_event!(MetaEvent::ParachainStaking(Event::NewRound(10, 2, 1, 20))); + assert_ok!(ParachainStaking::set_blocks_per_round(Origin::root(), 5u32)); + roll_to(18); + assert_last_event!(MetaEvent::ParachainStaking(Event::NewRound(18, 3, 1, 20))); }); } @@ -216,7 +297,7 @@ fn round_immediately_jumps_if_current_duration_exceeds_new_blocks_per_round() { fn invalid_monetary_origin_fails() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - Stake::set_staking_expectations( + ParachainStaking::set_staking_expectations( Origin::signed(45), Range { min: 3u32.into(), @@ -227,7 +308,7 @@ fn invalid_monetary_origin_fails() { sp_runtime::DispatchError::BadOrigin ); assert_noop!( - Stake::set_inflation( + ParachainStaking::set_inflation( Origin::signed(45), Range { min: Perbill::from_percent(3), @@ -238,7 +319,7 @@ fn invalid_monetary_origin_fails() { sp_runtime::DispatchError::BadOrigin ); assert_noop!( - Stake::set_inflation( + ParachainStaking::set_inflation( Origin::signed(45), Range { min: Perbill::from_percent(3), @@ -249,11 +330,11 @@ fn invalid_monetary_origin_fails() { sp_runtime::DispatchError::BadOrigin ); assert_noop!( - Stake::set_parachain_bond_account(Origin::signed(45), 11), + ParachainStaking::set_parachain_bond_account(Origin::signed(45), 11), sp_runtime::DispatchError::BadOrigin ); assert_noop!( - Stake::set_parachain_bond_reserve_percent( + ParachainStaking::set_parachain_bond_reserve_percent( Origin::signed(45), Percent::from_percent(2) ), @@ -268,7 +349,7 @@ fn invalid_monetary_origin_fails() { fn set_staking_event_emits_event_correctly() { ExtBuilder::default().build().execute_with(|| { // valid call succeeds - assert_ok!(Stake::set_staking_expectations( + assert_ok!(ParachainStaking::set_staking_expectations( Origin::root(), Range { min: 3u128, @@ -276,10 +357,9 @@ fn set_staking_event_emits_event_correctly() { max: 5u128, } )); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::StakeExpectationsSet(3u128, 4u128, 5u128)) - ); + assert_last_event!(MetaEvent::ParachainStaking(Event::StakeExpectationsSet( + 3u128, 4u128, 5u128, + ))); }); } @@ -287,14 +367,14 @@ fn set_staking_event_emits_event_correctly() { fn set_staking_updates_storage_correctly() { ExtBuilder::default().build().execute_with(|| { assert_eq!( - Stake::inflation_config().expect, + ParachainStaking::inflation_config().expect, Range { min: 700, ideal: 700, max: 700 } ); - assert_ok!(Stake::set_staking_expectations( + assert_ok!(ParachainStaking::set_staking_expectations( Origin::root(), Range { min: 3u128, @@ -303,7 +383,7 @@ fn set_staking_updates_storage_correctly() { } )); assert_eq!( - Stake::inflation_config().expect, + ParachainStaking::inflation_config().expect, Range { min: 3u128, ideal: 4u128, @@ -318,7 +398,7 @@ fn cannot_set_invalid_staking_expectations() { ExtBuilder::default().build().execute_with(|| { // invalid call fails assert_noop!( - Stake::set_staking_expectations( + ParachainStaking::set_staking_expectations( Origin::root(), Range { min: 5u128, @@ -334,7 +414,7 @@ fn cannot_set_invalid_staking_expectations() { #[test] fn cannot_set_same_staking_expectations() { ExtBuilder::default().build().execute_with(|| { - assert_ok!(Stake::set_staking_expectations( + assert_ok!(ParachainStaking::set_staking_expectations( Origin::root(), Range { min: 3u128, @@ -343,7 +423,7 @@ fn cannot_set_same_staking_expectations() { } )); assert_noop!( - Stake::set_staking_expectations( + ParachainStaking::set_staking_expectations( Origin::root(), Range { min: 3u128, @@ -366,21 +446,18 @@ fn set_inflation_event_emits_correctly() { Perbill::from_percent(4), Perbill::from_percent(5), ); - assert_ok!(Stake::set_inflation( + assert_ok!(ParachainStaking::set_inflation( Origin::root(), Range { min, ideal, max } )); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::InflationSet( - min, - ideal, - max, - Perbill::from_parts(57), - Perbill::from_parts(75), - Perbill::from_parts(93) - )) - ); + assert_last_event!(MetaEvent::ParachainStaking(Event::InflationSet( + min, + ideal, + max, + Perbill::from_parts(57), + Perbill::from_parts(75), + Perbill::from_parts(93), + ))); }); } @@ -393,7 +470,7 @@ fn set_inflation_storage_updates_correctly() { Perbill::from_percent(5), ); assert_eq!( - Stake::inflation_config().annual, + ParachainStaking::inflation_config().annual, Range { min: Perbill::from_percent(50), ideal: Perbill::from_percent(50), @@ -401,20 +478,23 @@ fn set_inflation_storage_updates_correctly() { } ); assert_eq!( - Stake::inflation_config().round, + ParachainStaking::inflation_config().round, Range { min: Perbill::from_percent(5), ideal: Perbill::from_percent(5), max: Perbill::from_percent(5) } ); - assert_ok!(Stake::set_inflation( + assert_ok!(ParachainStaking::set_inflation( Origin::root(), Range { min, ideal, max } ),); - assert_eq!(Stake::inflation_config().annual, Range { min, ideal, max }); assert_eq!( - Stake::inflation_config().round, + ParachainStaking::inflation_config().annual, + Range { min, ideal, max } + ); + assert_eq!( + ParachainStaking::inflation_config().round, Range { min: Perbill::from_parts(57), ideal: Perbill::from_parts(75), @@ -428,7 +508,7 @@ fn set_inflation_storage_updates_correctly() { fn cannot_set_invalid_inflation() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - Stake::set_inflation( + ParachainStaking::set_inflation( Origin::root(), Range { min: Perbill::from_percent(5), @@ -449,12 +529,12 @@ fn cannot_set_same_inflation() { Perbill::from_percent(4), Perbill::from_percent(5), ); - assert_ok!(Stake::set_inflation( + assert_ok!(ParachainStaking::set_inflation( Origin::root(), Range { min, ideal, max } ),); assert_noop!( - Stake::set_inflation(Origin::root(), Range { min, ideal, max }), + ParachainStaking::set_inflation(Origin::root(), Range { min, ideal, max }), Error::::NoWritingSameValue ); }); @@ -465,20 +545,25 @@ fn cannot_set_same_inflation() { #[test] fn set_parachain_bond_account_event_emits_correctly() { ExtBuilder::default().build().execute_with(|| { - assert_ok!(Stake::set_parachain_bond_account(Origin::root(), 11)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::ParachainBondAccountSet(0, 11)) - ); + assert_ok!(ParachainStaking::set_parachain_bond_account( + Origin::root(), + 11 + )); + assert_last_event!(MetaEvent::ParachainStaking(Event::ParachainBondAccountSet( + 0, 11 + ))); }); } #[test] fn set_parachain_bond_account_storage_updates_correctly() { ExtBuilder::default().build().execute_with(|| { - assert_eq!(Stake::parachain_bond_info().account, 0); - assert_ok!(Stake::set_parachain_bond_account(Origin::root(), 11)); - assert_eq!(Stake::parachain_bond_info().account, 11); + assert_eq!(ParachainStaking::parachain_bond_info().account, 0); + assert_ok!(ParachainStaking::set_parachain_bond_account( + Origin::root(), + 11 + )); + assert_eq!(ParachainStaking::parachain_bond_info().account, 11); }); } @@ -487,17 +572,16 @@ fn set_parachain_bond_account_storage_updates_correctly() { #[test] fn set_parachain_bond_reserve_percent_event_emits_correctly() { ExtBuilder::default().build().execute_with(|| { - assert_ok!(Stake::set_parachain_bond_reserve_percent( + assert_ok!(ParachainStaking::set_parachain_bond_reserve_percent( Origin::root(), Percent::from_percent(50) )); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::ParachainBondReservePercentSet( + assert_last_event!(MetaEvent::ParachainStaking( + Event::ParachainBondReservePercentSet( Percent::from_percent(30), - Percent::from_percent(50) - )) - ); + Percent::from_percent(50), + ) + )); }); } @@ -505,15 +589,15 @@ fn set_parachain_bond_reserve_percent_event_emits_correctly() { fn set_parachain_bond_reserve_percent_storage_updates_correctly() { ExtBuilder::default().build().execute_with(|| { assert_eq!( - Stake::parachain_bond_info().percent, + ParachainStaking::parachain_bond_info().percent, Percent::from_percent(30) ); - assert_ok!(Stake::set_parachain_bond_reserve_percent( + assert_ok!(ParachainStaking::set_parachain_bond_reserve_percent( Origin::root(), Percent::from_percent(50) )); assert_eq!( - Stake::parachain_bond_info().percent, + ParachainStaking::parachain_bond_info().percent, Percent::from_percent(50) ); }); @@ -523,7 +607,10 @@ fn set_parachain_bond_reserve_percent_storage_updates_correctly() { fn cannot_set_same_parachain_bond_reserve_percent() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - Stake::set_parachain_bond_reserve_percent(Origin::root(), Percent::from_percent(30)), + ParachainStaking::set_parachain_bond_reserve_percent( + Origin::root(), + Percent::from_percent(30) + ), Error::::NoWritingSameValue ); }); @@ -539,11 +626,14 @@ fn join_candidates_event_emits_correctly() { .with_balances(vec![(1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::join_candidates(Origin::signed(1), 10u128, 0u32)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::JoinedCollatorCandidates(1, 10u128, 10u128)) - ); + assert_ok!(ParachainStaking::join_candidates( + Origin::signed(1), + 10u128, + 0u32 + )); + assert_last_event!(MetaEvent::ParachainStaking( + Event::JoinedCollatorCandidates(1, 10u128, 10u128,) + )); }); } @@ -555,7 +645,11 @@ fn join_candidates_reserves_balance() { .execute_with(|| { assert_eq!(Balances::reserved_balance(&1), 0); assert_eq!(Balances::free_balance(&1), 10); - assert_ok!(Stake::join_candidates(Origin::signed(1), 10u128, 0u32)); + assert_ok!(ParachainStaking::join_candidates( + Origin::signed(1), + 10u128, + 0u32 + )); assert_eq!(Balances::reserved_balance(&1), 10); assert_eq!(Balances::free_balance(&1), 0); }); @@ -567,9 +661,13 @@ fn join_candidates_increases_total_staked() { .with_balances(vec![(1, 10)]) .build() .execute_with(|| { - assert_eq!(Stake::total(), 0); - assert_ok!(Stake::join_candidates(Origin::signed(1), 10u128, 0u32)); - assert_eq!(Stake::total(), 10); + assert_eq!(ParachainStaking::total(), 0); + assert_ok!(ParachainStaking::join_candidates( + Origin::signed(1), + 10u128, + 0u32 + )); + assert_eq!(ParachainStaking::total(), 10); }); } @@ -579,9 +677,14 @@ fn join_candidates_creates_candidate_state() { .with_balances(vec![(1, 10)]) .build() .execute_with(|| { - assert!(Stake::collator_state2(1).is_none()); - assert_ok!(Stake::join_candidates(Origin::signed(1), 10u128, 0u32)); - let candidate_state = Stake::collator_state2(1).expect("just joined => exists"); + assert!(ParachainStaking::candidate_info(1).is_none()); + assert_ok!(ParachainStaking::join_candidates( + Origin::signed(1), + 10u128, + 0u32 + )); + let candidate_state = + ParachainStaking::candidate_info(1).expect("just joined => exists"); assert_eq!(candidate_state.bond, 10u128); }); } @@ -592,16 +695,15 @@ fn join_candidates_adds_to_candidate_pool() { .with_balances(vec![(1, 10)]) .build() .execute_with(|| { - assert!(Stake::candidate_pool().0.is_empty()); - assert_ok!(Stake::join_candidates(Origin::signed(1), 10u128, 0u32)); - let candidate_pool = Stake::candidate_pool(); - assert_eq!( - candidate_pool.0[0], - Bond { - owner: 1, - amount: 10u128 - } - ); + assert!(ParachainStaking::candidate_pool().0.is_empty()); + assert_ok!(ParachainStaking::join_candidates( + Origin::signed(1), + 10u128, + 0u32 + )); + let candidate_pool = ParachainStaking::candidate_pool(); + assert_eq!(candidate_pool.0[0].owner, 1); + assert_eq!(candidate_pool.0[0].amount, 10); }); } @@ -613,23 +715,23 @@ fn cannot_join_candidates_if_candidate() { .build() .execute_with(|| { assert_noop!( - Stake::join_candidates(Origin::signed(1), 11u128, 100u32), + ParachainStaking::join_candidates(Origin::signed(1), 11u128, 100u32), Error::::CandidateExists ); }); } #[test] -fn cannot_join_candidates_if_nominator() { +fn cannot_join_candidates_if_delegator() { ExtBuilder::default() .with_balances(vec![(1, 50), (2, 20)]) .with_candidates(vec![(1, 50)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { assert_noop!( - Stake::join_candidates(Origin::signed(2), 10u128, 1u32), - Error::::NominatorExists + ParachainStaking::join_candidates(Origin::signed(2), 10u128, 1u32), + Error::::DelegatorExists ); }); } @@ -641,8 +743,8 @@ fn cannot_join_candidates_without_min_bond() { .build() .execute_with(|| { assert_noop!( - Stake::join_candidates(Origin::signed(1), 9u128, 100u32), - Error::::ValBondBelowMin + ParachainStaking::join_candidates(Origin::signed(1), 9u128, 100u32), + Error::::CandidateBondBelowMin ); }); } @@ -654,7 +756,7 @@ fn cannot_join_candidates_with_more_than_available_balance() { .build() .execute_with(|| { assert_noop!( - Stake::join_candidates(Origin::signed(1), 501u128, 100u32), + ParachainStaking::join_candidates(Origin::signed(1), 501u128, 100u32), DispatchError::Module { index: 1, error: 2, @@ -673,7 +775,7 @@ fn insufficient_join_candidates_weight_hint_fails() { .execute_with(|| { for i in 0..5 { assert_noop!( - Stake::join_candidates(Origin::signed(6), 20, i), + ParachainStaking::join_candidates(Origin::signed(6), 20, i), Error::::TooLowCandidateCountWeightHintJoinCandidates ); } @@ -699,13 +801,17 @@ fn sufficient_join_candidates_weight_hint_succeeds() { .execute_with(|| { let mut count = 5u32; for i in 6..10 { - assert_ok!(Stake::join_candidates(Origin::signed(i), 20, count)); + assert_ok!(ParachainStaking::join_candidates( + Origin::signed(i), + 20, + count + )); count += 1u32; } }); } -// LEAVE CANDIDATES +// SCHEDULE LEAVE CANDIDATES #[test] fn leave_candidates_event_emits_correctly() { @@ -714,43 +820,13 @@ fn leave_candidates_event_emits_correctly() { .with_candidates(vec![(1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::leave_candidates(Origin::signed(1), 1u32)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::CollatorScheduledExit(1, 1, 3)) - ); - }); -} - -#[test] -fn leave_candidates_unreserves_balance() { - ExtBuilder::default() - .with_balances(vec![(1, 10)]) - .with_candidates(vec![(1, 10)]) - .build() - .execute_with(|| { - roll_to(1); - assert_eq!(Balances::reserved_balance(&1), 10); - assert_eq!(Balances::free_balance(&1), 0); - assert_ok!(Stake::leave_candidates(Origin::signed(1), 1u32)); - roll_to(30); - assert_eq!(Balances::reserved_balance(&1), 0); - assert_eq!(Balances::free_balance(&1), 10); - }); -} - -#[test] -fn leave_candidates_decreases_total_staked() { - ExtBuilder::default() - .with_balances(vec![(1, 10)]) - .with_candidates(vec![(1, 10)]) - .build() - .execute_with(|| { - roll_to(1); - assert_eq!(Stake::total(), 10); - assert_ok!(Stake::leave_candidates(Origin::signed(1), 1u32)); - roll_to(30); - assert_eq!(Stake::total(), 0); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateScheduledExit( + 1, 1, 3 + ))); }); } @@ -761,26 +837,12 @@ fn leave_candidates_removes_candidate_from_candidate_pool() { .with_candidates(vec![(1, 10)]) .build() .execute_with(|| { - assert_eq!(Stake::candidate_pool().0.len(), 1); - assert_ok!(Stake::leave_candidates(Origin::signed(1), 1u32)); - assert!(Stake::candidate_pool().0.is_empty()); - }); -} - -#[test] -fn leave_candidates_removes_candidate_state_after_exit() { - ExtBuilder::default() - .with_balances(vec![(1, 10)]) - .with_candidates(vec![(1, 10)]) - .build() - .execute_with(|| { - roll_to(1); - assert_ok!(Stake::leave_candidates(Origin::signed(1), 1u32)); - // candidate state is not immediately removed - let candidate_state = Stake::collator_state2(1).expect("just left => still exists"); - assert_eq!(candidate_state.bond, 10u128); - roll_to(30); - assert!(Stake::collator_state2(1).is_none()); + assert_eq!(ParachainStaking::candidate_pool().0.len(), 1); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); + assert!(ParachainStaking::candidate_pool().0.is_empty()); }); } @@ -788,7 +850,7 @@ fn leave_candidates_removes_candidate_state_after_exit() { fn cannot_leave_candidates_if_not_candidate() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - Stake::leave_candidates(Origin::signed(1), 1u32), + ParachainStaking::schedule_leave_candidates(Origin::signed(1), 1u32), Error::::CandidateDNE ); }); @@ -801,9 +863,12 @@ fn cannot_leave_candidates_if_already_leaving_candidates() { .with_candidates(vec![(1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::leave_candidates(Origin::signed(1), 1u32)); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); assert_noop!( - Stake::leave_candidates(Origin::signed(1), 1u32), + ParachainStaking::schedule_leave_candidates(Origin::signed(1), 1u32), Error::::CandidateAlreadyLeaving ); }); @@ -818,8 +883,8 @@ fn insufficient_leave_candidates_weight_hint_fails() { .execute_with(|| { for i in 1..6 { assert_noop!( - Stake::leave_candidates(Origin::signed(i), 4u32), - Error::::TooLowCollatorCandidateCountToLeaveCandidates + ParachainStaking::schedule_leave_candidates(Origin::signed(i), 4u32), + Error::::TooLowCandidateCountToLeaveCandidates ); } }); @@ -834,141 +899,370 @@ fn sufficient_leave_candidates_weight_hint_succeeds() { .execute_with(|| { let mut count = 5u32; for i in 1..6 { - assert_ok!(Stake::leave_candidates(Origin::signed(i), count)); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(i), + count + )); count -= 1u32; } }); } -// GO OFFLINE +// EXECUTE LEAVE CANDIDATES #[test] -fn go_offline_event_emits_correctly() { +fn execute_leave_candidates_emits_event() { ExtBuilder::default() - .with_balances(vec![(1, 20)]) - .with_candidates(vec![(1, 20)]) + .with_balances(vec![(1, 10)]) + .with_candidates(vec![(1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::go_offline(Origin::signed(1))); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::CollatorWentOffline(1, 1)) - ); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(1), + 1, + 0 + )); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateLeft(1, 10, 0))); }); } #[test] -fn go_offline_removes_candidate_from_candidate_pool() { +fn execute_leave_candidates_callable_by_any_signed() { ExtBuilder::default() - .with_balances(vec![(1, 20)]) - .with_candidates(vec![(1, 20)]) + .with_balances(vec![(1, 10)]) + .with_candidates(vec![(1, 10)]) .build() .execute_with(|| { - assert_eq!(Stake::candidate_pool().0.len(), 1); - assert_ok!(Stake::go_offline(Origin::signed(1))); - assert!(Stake::candidate_pool().0.is_empty()); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(2), + 1, + 0 + )); }); } #[test] -fn go_offline_updates_candidate_state_to_idle() { +fn execute_leave_candidates_requires_correct_weight_hint() { ExtBuilder::default() - .with_balances(vec![(1, 20)]) - .with_candidates(vec![(1, 20)]) + .with_balances(vec![(1, 10), (2, 10), (3, 10), (4, 10)]) + .with_candidates(vec![(1, 10)]) + .with_delegations(vec![(2, 1, 10), (3, 1, 10), (4, 1, 10)]) .build() .execute_with(|| { - let candidate_state = Stake::collator_state2(1).expect("is active candidate"); - assert_eq!(candidate_state.state, CollatorStatus::Active); - assert_ok!(Stake::go_offline(Origin::signed(1))); - let candidate_state = Stake::collator_state2(1).expect("is candidate, just offline"); - assert_eq!(candidate_state.state, CollatorStatus::Idle); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); + roll_to(10); + for i in 0..3 { + assert_noop!( + ParachainStaking::execute_leave_candidates(Origin::signed(1), 1, i), + Error::::TooLowCandidateDelegationCountToLeaveCandidates + ); + } + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(2), + 1, + 3 + )); }); } #[test] -fn cannot_go_offline_if_not_candidate() { - ExtBuilder::default().build().execute_with(|| { - assert_noop!( - Stake::go_offline(Origin::signed(3)), - Error::::CandidateDNE - ); - }); +fn execute_leave_candidates_unreserves_balance() { + ExtBuilder::default() + .with_balances(vec![(1, 10)]) + .with_candidates(vec![(1, 10)]) + .build() + .execute_with(|| { + assert_eq!(Balances::reserved_balance(&1), 10); + assert_eq!(Balances::free_balance(&1), 0); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(1), + 1, + 0 + )); + assert_eq!(Balances::reserved_balance(&1), 0); + assert_eq!(Balances::free_balance(&1), 10); + }); } #[test] -fn cannot_go_offline_if_already_offline() { +fn execute_leave_candidates_decreases_total_staked() { ExtBuilder::default() - .with_balances(vec![(1, 20)]) - .with_candidates(vec![(1, 20)]) + .with_balances(vec![(1, 10)]) + .with_candidates(vec![(1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::go_offline(Origin::signed(1))); - assert_noop!( - Stake::go_offline(Origin::signed(1)), - Error::::AlreadyOffline - ); + assert_eq!(ParachainStaking::total(), 10); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(1), + 1, + 0 + )); + assert_eq!(ParachainStaking::total(), 0); }); } -// GO ONLINE - #[test] -fn go_online_event_emits_correctly() { +fn execute_leave_candidates_removes_candidate_state() { ExtBuilder::default() - .with_balances(vec![(1, 20)]) - .with_candidates(vec![(1, 20)]) + .with_balances(vec![(1, 10)]) + .with_candidates(vec![(1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::go_offline(Origin::signed(1))); - assert_ok!(Stake::go_online(Origin::signed(1))); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::CollatorBackOnline(1, 1)) - ); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); + // candidate state is not immediately removed + let candidate_state = + ParachainStaking::candidate_info(1).expect("just left => still exists"); + assert_eq!(candidate_state.bond, 10u128); + roll_to(10); + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(1), + 1, + 0 + )); + assert!(ParachainStaking::candidate_state(1).is_none()); }); } #[test] -fn go_online_adds_to_candidate_pool() { +fn cannot_execute_leave_candidates_before_delay() { ExtBuilder::default() - .with_balances(vec![(1, 20)]) - .with_candidates(vec![(1, 20)]) + .with_balances(vec![(1, 10)]) + .with_candidates(vec![(1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::go_offline(Origin::signed(1))); - assert!(Stake::candidate_pool().0.is_empty()); - assert_ok!(Stake::go_online(Origin::signed(1))); - assert_eq!( - Stake::candidate_pool().0[0], - Bond { - owner: 1, - amount: 20 - } + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); + assert_noop!( + ParachainStaking::execute_leave_candidates(Origin::signed(3), 1, 0), + Error::::CandidateCannotLeaveYet + ); + roll_to(9); + assert_noop!( + ParachainStaking::execute_leave_candidates(Origin::signed(3), 1, 0), + Error::::CandidateCannotLeaveYet ); + roll_to(10); + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(3), + 1, + 0 + )); }); } +// CANCEL LEAVE CANDIDATES + #[test] -fn go_online_storage_updates_candidate_state() { +fn cancel_leave_candidates_emits_event() { ExtBuilder::default() - .with_balances(vec![(1, 20)]) - .with_candidates(vec![(1, 20)]) + .with_balances(vec![(1, 10)]) + .with_candidates(vec![(1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::go_offline(Origin::signed(1))); - let candidate_state = Stake::collator_state2(1).expect("offline still exists"); - assert_eq!(candidate_state.state, CollatorStatus::Idle); - assert_ok!(Stake::go_online(Origin::signed(1))); - let candidate_state = Stake::collator_state2(1).expect("online so exists"); - assert_eq!(candidate_state.state, CollatorStatus::Active); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); + assert_ok!(ParachainStaking::cancel_leave_candidates( + Origin::signed(1), + 1 + )); + assert_last_event!(MetaEvent::ParachainStaking(Event::CancelledCandidateExit( + 1 + ))); }); } #[test] -fn cannot_go_online_if_not_candidate() { - ExtBuilder::default().build().execute_with(|| { +fn cancel_leave_candidates_updates_candidate_state() { + ExtBuilder::default() + .with_balances(vec![(1, 10)]) + .with_candidates(vec![(1, 10)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); + assert_ok!(ParachainStaking::cancel_leave_candidates( + Origin::signed(1), + 1 + )); + let candidate = + ParachainStaking::candidate_info(&1).expect("just cancelled leave so exists"); + assert!(candidate.is_active()); + }); +} + +#[test] +fn cancel_leave_candidates_adds_to_candidate_pool() { + ExtBuilder::default() + .with_balances(vec![(1, 10)]) + .with_candidates(vec![(1, 10)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1u32 + )); + assert_ok!(ParachainStaking::cancel_leave_candidates( + Origin::signed(1), + 1 + )); + assert_eq!(ParachainStaking::candidate_pool().0[0].owner, 1); + assert_eq!(ParachainStaking::candidate_pool().0[0].amount, 10); + }); +} + +// GO OFFLINE + +#[test] +fn go_offline_event_emits_correctly() { + ExtBuilder::default() + .with_balances(vec![(1, 20)]) + .with_candidates(vec![(1, 20)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::go_offline(Origin::signed(1))); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateWentOffline(1))); + }); +} + +#[test] +fn go_offline_removes_candidate_from_candidate_pool() { + ExtBuilder::default() + .with_balances(vec![(1, 20)]) + .with_candidates(vec![(1, 20)]) + .build() + .execute_with(|| { + assert_eq!(ParachainStaking::candidate_pool().0.len(), 1); + assert_ok!(ParachainStaking::go_offline(Origin::signed(1))); + assert!(ParachainStaking::candidate_pool().0.is_empty()); + }); +} + +#[test] +fn go_offline_updates_candidate_state_to_idle() { + ExtBuilder::default() + .with_balances(vec![(1, 20)]) + .with_candidates(vec![(1, 20)]) + .build() + .execute_with(|| { + let candidate_state = + ParachainStaking::candidate_info(1).expect("is active candidate"); + assert_eq!(candidate_state.status, CollatorStatus::Active); + assert_ok!(ParachainStaking::go_offline(Origin::signed(1))); + let candidate_state = + ParachainStaking::candidate_info(1).expect("is candidate, just offline"); + assert_eq!(candidate_state.status, CollatorStatus::Idle); + }); +} + +#[test] +fn cannot_go_offline_if_not_candidate() { + ExtBuilder::default().build().execute_with(|| { + assert_noop!( + ParachainStaking::go_offline(Origin::signed(3)), + Error::::CandidateDNE + ); + }); +} + +#[test] +fn cannot_go_offline_if_already_offline() { + ExtBuilder::default() + .with_balances(vec![(1, 20)]) + .with_candidates(vec![(1, 20)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::go_offline(Origin::signed(1))); + assert_noop!( + ParachainStaking::go_offline(Origin::signed(1)), + Error::::AlreadyOffline + ); + }); +} + +// GO ONLINE + +#[test] +fn go_online_event_emits_correctly() { + ExtBuilder::default() + .with_balances(vec![(1, 20)]) + .with_candidates(vec![(1, 20)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::go_offline(Origin::signed(1))); + assert_ok!(ParachainStaking::go_online(Origin::signed(1))); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateBackOnline(1))); + }); +} + +#[test] +fn go_online_adds_to_candidate_pool() { + ExtBuilder::default() + .with_balances(vec![(1, 20)]) + .with_candidates(vec![(1, 20)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::go_offline(Origin::signed(1))); + assert!(ParachainStaking::candidate_pool().0.is_empty()); + assert_ok!(ParachainStaking::go_online(Origin::signed(1))); + assert_eq!(ParachainStaking::candidate_pool().0[0].owner, 1); + assert_eq!(ParachainStaking::candidate_pool().0[0].amount, 20); + }); +} + +#[test] +fn go_online_storage_updates_candidate_state() { + ExtBuilder::default() + .with_balances(vec![(1, 20)]) + .with_candidates(vec![(1, 20)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::go_offline(Origin::signed(1))); + let candidate_state = + ParachainStaking::candidate_info(1).expect("offline still exists"); + assert_eq!(candidate_state.status, CollatorStatus::Idle); + assert_ok!(ParachainStaking::go_online(Origin::signed(1))); + let candidate_state = ParachainStaking::candidate_info(1).expect("online so exists"); + assert_eq!(candidate_state.status, CollatorStatus::Active); + }); +} + +#[test] +fn cannot_go_online_if_not_candidate() { + ExtBuilder::default().build().execute_with(|| { assert_noop!( - Stake::go_online(Origin::signed(3)), + ParachainStaking::go_online(Origin::signed(3)), Error::::CandidateDNE ); }); @@ -982,26 +1276,43 @@ fn cannot_go_online_if_already_online() { .build() .execute_with(|| { assert_noop!( - Stake::go_online(Origin::signed(1)), + ParachainStaking::go_online(Origin::signed(1)), Error::::AlreadyActive ); }); } +#[test] +fn cannot_go_online_if_leaving() { + ExtBuilder::default() + .with_balances(vec![(1, 20)]) + .with_candidates(vec![(1, 20)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1 + )); + assert_noop!( + ParachainStaking::go_online(Origin::signed(1)), + Error::::CannotGoOnlineIfLeaving + ); + }); +} + // CANDIDATE BOND MORE #[test] -fn candidate_bond_more_event_emits_correctly() { +fn candidate_bond_more_emits_correct_event() { ExtBuilder::default() .with_balances(vec![(1, 50)]) .with_candidates(vec![(1, 20)]) .build() .execute_with(|| { - assert_ok!(Stake::candidate_bond_more(Origin::signed(1), 30)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::CollatorBondedMore(1, 20, 50)) - ); + assert_ok!(ParachainStaking::candidate_bond_more(Origin::signed(1), 30)); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateBondedMore( + 1, 30, 50 + ))); }); } @@ -1014,7 +1325,7 @@ fn candidate_bond_more_reserves_balance() { .execute_with(|| { assert_eq!(Balances::reserved_balance(&1), 20); assert_eq!(Balances::free_balance(&1), 30); - assert_ok!(Stake::candidate_bond_more(Origin::signed(1), 30)); + assert_ok!(ParachainStaking::candidate_bond_more(Origin::signed(1), 30)); assert_eq!(Balances::reserved_balance(&1), 50); assert_eq!(Balances::free_balance(&1), 0); }); @@ -1027,10 +1338,10 @@ fn candidate_bond_more_increases_total() { .with_candidates(vec![(1, 20)]) .build() .execute_with(|| { - let mut total = Stake::total(); - assert_ok!(Stake::candidate_bond_more(Origin::signed(1), 30)); + let mut total = ParachainStaking::total(); + assert_ok!(ParachainStaking::candidate_bond_more(Origin::signed(1), 30)); total += 30; - assert_eq!(Stake::total(), total); + assert_eq!(ParachainStaking::total(), total); }); } @@ -1041,10 +1352,10 @@ fn candidate_bond_more_updates_candidate_state() { .with_candidates(vec![(1, 20)]) .build() .execute_with(|| { - let candidate_state = Stake::collator_state2(1).expect("updated => exists"); + let candidate_state = ParachainStaking::candidate_info(1).expect("updated => exists"); assert_eq!(candidate_state.bond, 20); - assert_ok!(Stake::candidate_bond_more(Origin::signed(1), 30)); - let candidate_state = Stake::collator_state2(1).expect("updated => exists"); + assert_ok!(ParachainStaking::candidate_bond_more(Origin::signed(1), 30)); + let candidate_state = ParachainStaking::candidate_info(1).expect("updated => exists"); assert_eq!(candidate_state.bond, 50); }); } @@ -1056,103 +1367,143 @@ fn candidate_bond_more_updates_candidate_pool() { .with_candidates(vec![(1, 20)]) .build() .execute_with(|| { - assert_eq!( - Stake::candidate_pool().0[0], - Bond { - owner: 1, - amount: 20 - } - ); - assert_ok!(Stake::candidate_bond_more(Origin::signed(1), 30)); - assert_eq!( - Stake::candidate_pool().0[0], - Bond { - owner: 1, - amount: 50 - } + assert_eq!(ParachainStaking::candidate_pool().0[0].owner, 1); + assert_eq!(ParachainStaking::candidate_pool().0[0].amount, 20); + assert_ok!(ParachainStaking::candidate_bond_more(Origin::signed(1), 30)); + assert_eq!(ParachainStaking::candidate_pool().0[0].owner, 1); + assert_eq!(ParachainStaking::candidate_pool().0[0].amount, 50); + }); +} + +// SCHEDULE CANDIDATE BOND LESS + +#[test] +fn schedule_candidate_bond_less_event_emits_correctly() { + ExtBuilder::default() + .with_balances(vec![(1, 30)]) + .with_candidates(vec![(1, 30)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_candidate_bond_less( + Origin::signed(1), + 10 + )); + assert_last_event!(MetaEvent::ParachainStaking( + Event::CandidateBondLessRequested(1, 10, 3,) + )); + }); +} + +#[test] +fn cannot_schedule_candidate_bond_less_if_request_exists() { + ExtBuilder::default() + .with_balances(vec![(1, 30)]) + .with_candidates(vec![(1, 30)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_candidate_bond_less( + Origin::signed(1), + 5 + )); + assert_noop!( + ParachainStaking::schedule_candidate_bond_less(Origin::signed(1), 5), + Error::::PendingCandidateRequestAlreadyExists ); }); } #[test] -fn cannot_candidate_bond_more_if_not_candidate() { +fn cannot_schedule_candidate_bond_less_if_not_candidate() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - Stake::candidate_bond_more(Origin::signed(6), 50), + ParachainStaking::schedule_candidate_bond_less(Origin::signed(6), 50), Error::::CandidateDNE ); }); } #[test] -fn cannot_candidate_bond_more_if_insufficient_balance() { +fn cannot_schedule_candidate_bond_less_if_new_total_below_min_candidate_stk() { ExtBuilder::default() .with_balances(vec![(1, 30)]) .with_candidates(vec![(1, 30)]) .build() .execute_with(|| { assert_noop!( - Stake::candidate_bond_more(Origin::signed(1), 1), - DispatchError::Module { - index: 1, - error: 2, - message: Some("InsufficientBalance") - } + ParachainStaking::schedule_candidate_bond_less(Origin::signed(1), 21), + Error::::CandidateBondBelowMin ); }); } #[test] -fn cannot_candidate_bond_more_if_leaving_candidates() { +fn can_schedule_candidate_bond_less_if_leaving_candidates() { ExtBuilder::default() - .with_balances(vec![(1, 50)]) - .with_candidates(vec![(1, 20)]) + .with_balances(vec![(1, 30)]) + .with_candidates(vec![(1, 30)]) .build() .execute_with(|| { - assert_ok!(Stake::leave_candidates(Origin::signed(1), 1)); - assert_noop!( - Stake::candidate_bond_more(Origin::signed(1), 30), - Error::::CannotActBecauseLeaving - ); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1 + )); + assert_ok!(ParachainStaking::schedule_candidate_bond_less( + Origin::signed(1), + 10 + )); }); } #[test] -fn cannot_candidate_bond_more_if_exited_candidates() { +fn cannot_schedule_candidate_bond_less_if_exited_candidates() { ExtBuilder::default() - .with_balances(vec![(1, 50)]) - .with_candidates(vec![(1, 20)]) + .with_balances(vec![(1, 30)]) + .with_candidates(vec![(1, 30)]) .build() .execute_with(|| { - roll_to(4); - assert_ok!(Stake::leave_candidates(Origin::signed(1), 1)); - roll_to(30); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(1), + 1, + 0 + )); assert_noop!( - Stake::candidate_bond_more(Origin::signed(1), 30), + ParachainStaking::schedule_candidate_bond_less(Origin::signed(1), 10), Error::::CandidateDNE ); }); } -// CANDIDATE BOND LESS +// 2. EXECUTE BOND LESS REQUEST #[test] -fn candidate_bond_less_event_emits_correctly() { +fn execute_candidate_bond_less_emits_correct_event() { ExtBuilder::default() - .with_balances(vec![(1, 30)]) - .with_candidates(vec![(1, 30)]) + .with_balances(vec![(1, 50)]) + .with_candidates(vec![(1, 50)]) .build() .execute_with(|| { - assert_ok!(Stake::candidate_bond_less(Origin::signed(1), 10)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::CollatorBondedLess(1, 30, 20)) - ); + assert_ok!(ParachainStaking::schedule_candidate_bond_less( + Origin::signed(1), + 30 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_candidate_bond_less( + Origin::signed(1), + 1 + )); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateBondedLess( + 1, 30, 20 + ))); }); } #[test] -fn candidate_bond_less_unreserves_balance() { +fn execute_candidate_bond_less_unreserves_balance() { ExtBuilder::default() .with_balances(vec![(1, 30)]) .with_candidates(vec![(1, 30)]) @@ -1160,117 +1511,144 @@ fn candidate_bond_less_unreserves_balance() { .execute_with(|| { assert_eq!(Balances::reserved_balance(&1), 30); assert_eq!(Balances::free_balance(&1), 0); - assert_ok!(Stake::candidate_bond_less(Origin::signed(1), 10)); + assert_ok!(ParachainStaking::schedule_candidate_bond_less( + Origin::signed(1), + 10 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_candidate_bond_less( + Origin::signed(1), + 1 + )); assert_eq!(Balances::reserved_balance(&1), 20); assert_eq!(Balances::free_balance(&1), 10); }); } #[test] -fn candidate_bond_less_decreases_total() { +fn execute_candidate_bond_less_decreases_total() { ExtBuilder::default() .with_balances(vec![(1, 30)]) .with_candidates(vec![(1, 30)]) .build() .execute_with(|| { - let mut total = Stake::total(); - assert_ok!(Stake::candidate_bond_less(Origin::signed(1), 10)); + let mut total = ParachainStaking::total(); + assert_ok!(ParachainStaking::schedule_candidate_bond_less( + Origin::signed(1), + 10 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_candidate_bond_less( + Origin::signed(1), + 1 + )); total -= 10; - assert_eq!(Stake::total(), total); + assert_eq!(ParachainStaking::total(), total); }); } #[test] -fn candidate_bond_less_updates_candidate_state() { +fn execute_candidate_bond_less_updates_candidate_state() { ExtBuilder::default() .with_balances(vec![(1, 30)]) .with_candidates(vec![(1, 30)]) .build() .execute_with(|| { - let candidate_state = Stake::collator_state2(1).expect("updated => exists"); + let candidate_state = ParachainStaking::candidate_info(1).expect("updated => exists"); assert_eq!(candidate_state.bond, 30); - assert_ok!(Stake::candidate_bond_less(Origin::signed(1), 10)); - let candidate_state = Stake::collator_state2(1).expect("updated => exists"); + assert_ok!(ParachainStaking::schedule_candidate_bond_less( + Origin::signed(1), + 10 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_candidate_bond_less( + Origin::signed(1), + 1 + )); + let candidate_state = ParachainStaking::candidate_info(1).expect("updated => exists"); assert_eq!(candidate_state.bond, 20); }); } #[test] -fn candidate_bond_less_updates_candidate_pool() { +fn execute_candidate_bond_less_updates_candidate_pool() { ExtBuilder::default() .with_balances(vec![(1, 30)]) .with_candidates(vec![(1, 30)]) .build() .execute_with(|| { - assert_eq!( - Stake::candidate_pool().0[0], - Bond { - owner: 1, - amount: 30 - } - ); - assert_ok!(Stake::candidate_bond_less(Origin::signed(1), 10)); - assert_eq!( - Stake::candidate_pool().0[0], - Bond { - owner: 1, - amount: 20 - } - ); + assert_eq!(ParachainStaking::candidate_pool().0[0].owner, 1); + assert_eq!(ParachainStaking::candidate_pool().0[0].amount, 30); + assert_ok!(ParachainStaking::schedule_candidate_bond_less( + Origin::signed(1), + 10 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_candidate_bond_less( + Origin::signed(1), + 1 + )); + assert_eq!(ParachainStaking::candidate_pool().0[0].owner, 1); + assert_eq!(ParachainStaking::candidate_pool().0[0].amount, 20); }); } -#[test] -fn cannot_candidate_bond_less_if_not_candidate() { - ExtBuilder::default().build().execute_with(|| { - assert_noop!( - Stake::candidate_bond_less(Origin::signed(6), 50), - Error::::CandidateDNE - ); - }); -} +// CANCEL CANDIDATE BOND LESS REQUEST #[test] -fn cannot_candidate_bond_less_if_new_total_below_min_candidate_stk() { +fn cancel_candidate_bond_less_emits_event() { ExtBuilder::default() .with_balances(vec![(1, 30)]) .with_candidates(vec![(1, 30)]) .build() .execute_with(|| { - assert_noop!( - Stake::candidate_bond_less(Origin::signed(1), 21), - Error::::ValBondBelowMin - ); + assert_ok!(ParachainStaking::schedule_candidate_bond_less( + Origin::signed(1), + 10 + )); + assert_ok!(ParachainStaking::cancel_candidate_bond_less( + Origin::signed(1) + )); + assert_last_event!(MetaEvent::ParachainStaking( + Event::CancelledCandidateBondLess(1, 10, 3,) + )); }); } #[test] -fn cannot_candidate_bond_less_if_leaving_candidates() { +fn cancel_candidate_bond_less_updates_candidate_state() { ExtBuilder::default() .with_balances(vec![(1, 30)]) .with_candidates(vec![(1, 30)]) .build() .execute_with(|| { - assert_ok!(Stake::leave_candidates(Origin::signed(1), 1)); - assert_noop!( - Stake::candidate_bond_less(Origin::signed(1), 10), - Error::::CannotActBecauseLeaving - ); + assert_ok!(ParachainStaking::schedule_candidate_bond_less( + Origin::signed(1), + 10 + )); + assert_ok!(ParachainStaking::cancel_candidate_bond_less( + Origin::signed(1) + )); + assert!(ParachainStaking::candidate_info(&1) + .unwrap() + .request + .is_none()); }); } #[test] -fn cannot_candidate_bond_less_if_exited_candidates() { +fn only_candidate_can_cancel_candidate_bond_less_request() { ExtBuilder::default() .with_balances(vec![(1, 30)]) .with_candidates(vec![(1, 30)]) .build() .execute_with(|| { - roll_to(4); - assert_ok!(Stake::leave_candidates(Origin::signed(1), 1)); - roll_to(30); + assert_ok!(ParachainStaking::schedule_candidate_bond_less( + Origin::signed(1), + 10 + )); assert_noop!( - Stake::candidate_bond_less(Origin::signed(1), 10), + ParachainStaking::cancel_candidate_bond_less(Origin::signed(2)), Error::::CandidateDNE ); }); @@ -1279,27 +1657,24 @@ fn cannot_candidate_bond_less_if_exited_candidates() { // NOMINATE #[test] -fn nominate_event_emits_correctly() { +fn delegate_event_emits_correctly() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) .build() .execute_with(|| { - assert_ok!(Stake::nominate(Origin::signed(2), 1, 10, 0, 0)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::Nomination( - 2, - 10, - 1, - NominatorAdded::AddedToTop { new_total: 40 } - )), - ); + assert_ok!(ParachainStaking::delegate(Origin::signed(2), 1, 10, 0, 0)); + assert_last_event!(MetaEvent::ParachainStaking(Event::Delegation( + 2, + 10, + 1, + DelegatorAdded::AddedToTop { new_total: 40 }, + ))); }); } #[test] -fn nominate_reserves_balance() { +fn delegate_reserves_balance() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) @@ -1307,144 +1682,146 @@ fn nominate_reserves_balance() { .execute_with(|| { assert_eq!(Balances::reserved_balance(&2), 0); assert_eq!(Balances::free_balance(&2), 10); - assert_ok!(Stake::nominate(Origin::signed(2), 1, 10, 0, 0)); + assert_ok!(ParachainStaking::delegate(Origin::signed(2), 1, 10, 0, 0)); assert_eq!(Balances::reserved_balance(&2), 10); assert_eq!(Balances::free_balance(&2), 0); }); } #[test] -fn nominate_updates_nominator_state() { +fn delegate_updates_delegator_state() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) .build() .execute_with(|| { - assert!(Stake::nominator_state2(2).is_none()); - assert_ok!(Stake::nominate(Origin::signed(2), 1, 10, 0, 0)); - let nominator_state = Stake::nominator_state2(2).expect("just nominated => exists"); - assert_eq!(nominator_state.total, 10); - assert_eq!( - nominator_state.nominations.0[0], - Bond { - owner: 1, - amount: 10 - } - ); + assert!(ParachainStaking::delegator_state(2).is_none()); + assert_ok!(ParachainStaking::delegate(Origin::signed(2), 1, 10, 0, 0)); + let delegator_state = + ParachainStaking::delegator_state(2).expect("just delegated => exists"); + assert_eq!(delegator_state.total, 10); + assert_eq!(delegator_state.delegations.0[0].owner, 1); + assert_eq!(delegator_state.delegations.0[0].amount, 10); }); } #[test] -fn nominate_updates_collator_state() { +fn delegate_updates_collator_state() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) .build() .execute_with(|| { - let candidate_state = Stake::collator_state2(1).expect("registered in genesis"); - assert_eq!(candidate_state.total_backing, 30); + let candidate_state = + ParachainStaking::candidate_info(1).expect("registered in genesis"); assert_eq!(candidate_state.total_counted, 30); - assert!(candidate_state.top_nominators.is_empty()); - assert_ok!(Stake::nominate(Origin::signed(2), 1, 10, 0, 0)); - let candidate_state = Stake::collator_state2(1).expect("just nominated => exists"); - assert_eq!(candidate_state.total_backing, 40); + let top_delegations = + ParachainStaking::top_delegations(1).expect("registered in genesis"); + assert!(top_delegations.delegations.is_empty()); + assert!(top_delegations.total.is_zero()); + assert_ok!(ParachainStaking::delegate(Origin::signed(2), 1, 10, 0, 0)); + let candidate_state = + ParachainStaking::candidate_info(1).expect("just delegated => exists"); assert_eq!(candidate_state.total_counted, 40); - assert_eq!( - candidate_state.top_nominators[0], - Bond { - owner: 2, - amount: 10 - } - ); + let top_delegations = + ParachainStaking::top_delegations(1).expect("just delegated => exists"); + assert_eq!(top_delegations.delegations[0].owner, 2); + assert_eq!(top_delegations.delegations[0].amount, 10); + assert_eq!(top_delegations.total, 10); }); } #[test] -fn can_nominate_immediately_after_other_join_candidates() { +fn can_delegate_immediately_after_other_join_candidates() { ExtBuilder::default() .with_balances(vec![(1, 20), (2, 20)]) .build() .execute_with(|| { - assert_ok!(Stake::join_candidates(Origin::signed(1), 20, 0)); - assert_ok!(Stake::nominate(Origin::signed(2), 1, 20, 0, 0)); + assert_ok!(ParachainStaking::join_candidates(Origin::signed(1), 20, 0)); + assert_ok!(ParachainStaking::delegate(Origin::signed(2), 1, 20, 0, 0)); }); } #[test] -fn can_nominate_if_revoking() { +fn can_delegate_if_revoking() { ExtBuilder::default() .with_balances(vec![(1, 20), (2, 30), (3, 20), (4, 20)]) .with_candidates(vec![(1, 20), (3, 20), (4, 20)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - assert_ok!(Stake::nominate(Origin::signed(2), 4, 10, 0, 2)); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + assert_ok!(ParachainStaking::delegate(Origin::signed(2), 4, 10, 0, 2)); }); } #[test] -fn cannot_nominate_if_leaving() { +fn cannot_delegate_if_leaving() { ExtBuilder::default() - .with_balances(vec![(1, 20), (2, 20)]) - .with_candidates(vec![(1, 20)]) - .with_nominations(vec![(2, 1, 10)]) + .with_balances(vec![(1, 20), (2, 20), (3, 20)]) + .with_candidates(vec![(1, 20), (3, 20)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::leave_nominators(Origin::signed(2), 1)); + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); assert_noop!( - Stake::nominate(Origin::signed(2), 1, 10, 0, 0), - Error::::CannotActBecauseLeaving + ParachainStaking::delegate(Origin::signed(2), 3, 10, 0, 1), + Error::::CannotDelegateIfLeaving ); }); } #[test] -fn cannot_nominate_if_candidate() { +fn cannot_delegate_if_candidate() { ExtBuilder::default() - .with_balances(vec![(1, 20), (2, 20)]) + .with_balances(vec![(1, 20), (2, 30)]) .with_candidates(vec![(1, 20), (2, 20)]) .build() .execute_with(|| { assert_noop!( - Stake::nominate(Origin::signed(2), 1, 10, 0, 0), + ParachainStaking::delegate(Origin::signed(2), 1, 10, 0, 0), Error::::CandidateExists ); }); } #[test] -fn cannot_nominate_if_already_nominated() { +fn cannot_delegate_if_already_delegated() { ExtBuilder::default() .with_balances(vec![(1, 20), (2, 30)]) .with_candidates(vec![(1, 20)]) - .with_nominations(vec![(2, 1, 20)]) + .with_delegations(vec![(2, 1, 20)]) .build() .execute_with(|| { assert_noop!( - Stake::nominate(Origin::signed(2), 1, 10, 1, 1), - Error::::AlreadyNominatedCollator + ParachainStaking::delegate(Origin::signed(2), 1, 10, 1, 1), + Error::::AlreadyDelegatedCandidate ); }); } #[test] -fn cannot_nominate_more_than_max_nominations() { +fn cannot_delegate_more_than_max_delegations() { ExtBuilder::default() .with_balances(vec![(1, 20), (2, 50), (3, 20), (4, 20), (5, 20), (6, 20)]) .with_candidates(vec![(1, 20), (3, 20), (4, 20), (5, 20), (6, 20)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10), (2, 4, 10), (2, 5, 10)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10), (2, 4, 10), (2, 5, 10)]) .build() .execute_with(|| { assert_noop!( - Stake::nominate(Origin::signed(2), 6, 10, 0, 4), - Error::::ExceedMaxCollatorsPerNom, + ParachainStaking::delegate(Origin::signed(2), 6, 10, 0, 4), + Error::::ExceedMaxDelegationsPerDelegator, ); }); } #[test] -fn sufficient_nominate_weight_hint_succeeds() { +fn sufficient_delegate_weight_hint_succeeds() { ExtBuilder::default() .with_balances(vec![ (1, 20), @@ -1459,24 +1836,36 @@ fn sufficient_nominate_weight_hint_succeeds() { (10, 20), ]) .with_candidates(vec![(1, 20), (2, 20)]) - .with_nominations(vec![(3, 1, 10), (4, 1, 10), (5, 1, 10), (6, 1, 10)]) + .with_delegations(vec![(3, 1, 10), (4, 1, 10), (5, 1, 10), (6, 1, 10)]) .build() .execute_with(|| { let mut count = 4u32; for i in 7..11 { - assert_ok!(Stake::nominate(Origin::signed(i), 1, 10, count, 0u32)); + assert_ok!(ParachainStaking::delegate( + Origin::signed(i), + 1, + 10, + count, + 0u32 + )); count += 1u32; } let mut count = 0u32; for i in 3..11 { - assert_ok!(Stake::nominate(Origin::signed(i), 2, 10, count, 1u32)); + assert_ok!(ParachainStaking::delegate( + Origin::signed(i), + 2, + 10, + count, + 1u32 + )); count += 1u32; } }); } #[test] -fn insufficient_nominate_weight_hint_fails() { +fn insufficient_delegate_weight_hint_fails() { ExtBuilder::default() .with_balances(vec![ (1, 20), @@ -1491,1026 +1880,1346 @@ fn insufficient_nominate_weight_hint_fails() { (10, 20), ]) .with_candidates(vec![(1, 20), (2, 20)]) - .with_nominations(vec![(3, 1, 10), (4, 1, 10), (5, 1, 10), (6, 1, 10)]) + .with_delegations(vec![(3, 1, 10), (4, 1, 10), (5, 1, 10), (6, 1, 10)]) .build() .execute_with(|| { let mut count = 3u32; for i in 7..11 { assert_noop!( - Stake::nominate(Origin::signed(i), 1, 10, count, 0u32), - Error::::TooLowCollatorNominationCountToNominate + ParachainStaking::delegate(Origin::signed(i), 1, 10, count, 0u32), + Error::::TooLowCandidateDelegationCountToDelegate ); } // to set up for next error test count = 4u32; for i in 7..11 { - assert_ok!(Stake::nominate(Origin::signed(i), 1, 10, count, 0u32)); + assert_ok!(ParachainStaking::delegate( + Origin::signed(i), + 1, + 10, + count, + 0u32 + )); count += 1u32; } count = 0u32; for i in 3..11 { assert_noop!( - Stake::nominate(Origin::signed(i), 2, 10, count, 0u32), - Error::::TooLowNominationCountToNominate + ParachainStaking::delegate(Origin::signed(i), 2, 10, count, 0u32), + Error::::TooLowDelegationCountToDelegate ); count += 1u32; } }); } -// LEAVE_NOMINATORS +// SCHEDULE LEAVE DELEGATORS #[test] -fn leave_nominators_event_emits_correctly() { +fn schedule_leave_delegators_event_emits_correctly() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - roll_to(1); - assert_ok!(Stake::leave_nominators(Origin::signed(2), 1)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::NominatorExitScheduled(1, 2, 3)) + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); + assert_last_event!(MetaEvent::ParachainStaking(Event::DelegatorExitScheduled( + 1, 2, 3 + ))); + }); +} + +#[test] +fn cannot_schedule_leave_delegators_if_already_leaving() { + ExtBuilder::default() + .with_balances(vec![(1, 30), (2, 10)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 10)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); + assert_noop!( + ParachainStaking::schedule_leave_delegators(Origin::signed(2)), + Error::::DelegatorAlreadyLeaving + ); + }); +} + +#[test] +fn cannot_schedule_leave_delegators_if_not_delegator() { + ExtBuilder::default() + .with_balances(vec![(1, 30), (2, 10)]) + .with_candidates(vec![(1, 30)]) + .build() + .execute_with(|| { + assert_noop!( + ParachainStaking::schedule_leave_delegators(Origin::signed(2)), + Error::::DelegatorDNE ); + }); +} + +// EXECUTE LEAVE DELEGATORS + +#[test] +fn execute_leave_delegators_event_emits_correctly() { + ExtBuilder::default() + .with_balances(vec![(1, 30), (2, 10)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 10)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); roll_to(10); - assert!(events().contains(&Event::NominatorLeft(2, 10))); + assert_ok!(ParachainStaking::execute_leave_delegators( + Origin::signed(2), + 2, + 1 + )); + assert_event_emitted!(Event::DelegatorLeft(2, 10)); }); } #[test] -fn leave_nominators_unreserves_balance() { +fn execute_leave_delegators_unreserves_balance() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - roll_to(1); assert_eq!(Balances::reserved_balance(&2), 10); assert_eq!(Balances::free_balance(&2), 0); - assert_ok!(Stake::leave_nominators(Origin::signed(2), 1)); + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); roll_to(10); + assert_ok!(ParachainStaking::execute_leave_delegators( + Origin::signed(2), + 2, + 1 + )); assert_eq!(Balances::reserved_balance(&2), 0); assert_eq!(Balances::free_balance(&2), 10); }); } #[test] -fn leave_nominators_decreases_total_staked() { +fn execute_leave_delegators_decreases_total_staked() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - roll_to(1); - assert_eq!(Stake::total(), 40); - assert_ok!(Stake::leave_nominators(Origin::signed(2), 1)); + assert_eq!(ParachainStaking::total(), 40); + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); roll_to(10); - assert_eq!(Stake::total(), 30); + assert_ok!(ParachainStaking::execute_leave_delegators( + Origin::signed(2), + 2, + 1 + )); + assert_eq!(ParachainStaking::total(), 30); }); } #[test] -fn leave_nominators_removes_nominator_state() { +fn execute_leave_delegators_removes_delegator_state() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - roll_to(1); - assert!(Stake::nominator_state2(2).is_some()); - assert_ok!(Stake::leave_nominators(Origin::signed(2), 1)); + assert!(ParachainStaking::delegator_state(2).is_some()); + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); roll_to(10); - assert!(Stake::nominator_state2(2).is_none()); + assert_ok!(ParachainStaking::execute_leave_delegators( + Origin::signed(2), + 2, + 1 + )); + assert!(ParachainStaking::delegator_state(2).is_none()); }); } #[test] -fn leave_nominators_removes_nominations_from_collator_state() { +fn execute_leave_delegators_removes_delegations_from_collator_state() { ExtBuilder::default() .with_balances(vec![(1, 100), (2, 20), (3, 20), (4, 20), (5, 20)]) .with_candidates(vec![(2, 20), (3, 20), (4, 20), (5, 20)]) - .with_nominations(vec![(1, 2, 10), (1, 3, 10), (1, 4, 10), (1, 5, 10)]) + .with_delegations(vec![(1, 2, 10), (1, 3, 10), (1, 4, 10), (1, 5, 10)]) .build() .execute_with(|| { - roll_to(1); for i in 2..6 { let candidate_state = - Stake::collator_state2(i).expect("initialized in ext builder"); - assert_eq!( - candidate_state.top_nominators[0], - Bond { - owner: 1, - amount: 10 - } - ); - assert_eq!(candidate_state.nominators.0[0], 1); - assert_eq!(candidate_state.total_backing, 30); + ParachainStaking::candidate_info(i).expect("initialized in ext builder"); + assert_eq!(candidate_state.total_counted, 30); + let top_delegations = + ParachainStaking::top_delegations(i).expect("initialized in ext builder"); + assert_eq!(top_delegations.delegations[0].owner, 1); + assert_eq!(top_delegations.delegations[0].amount, 10); + assert_eq!(top_delegations.total, 10); } assert_eq!( - Stake::nominator_state2(1).unwrap().nominations.0.len(), + ParachainStaking::delegator_state(1) + .unwrap() + .delegations + .0 + .len(), 4usize ); - assert_ok!(Stake::leave_nominators(Origin::signed(1), 10)); + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 1 + ))); roll_to(10); + assert_ok!(ParachainStaking::execute_leave_delegators( + Origin::signed(1), + 1, + 10 + )); for i in 2..6 { let candidate_state = - Stake::collator_state2(i).expect("initialized in ext builder"); - assert!(candidate_state.top_nominators.is_empty()); - assert!(candidate_state.nominators.0.is_empty()); - assert_eq!(candidate_state.total_backing, 20); + ParachainStaking::candidate_info(i).expect("initialized in ext builder"); + assert_eq!(candidate_state.total_counted, 20); + let top_delegations = + ParachainStaking::top_delegations(i).expect("initialized in ext builder"); + assert!(top_delegations.delegations.is_empty()); } }); } #[test] -fn cannot_leave_nominators_if_leaving_through_revoking_last_nomination() { - ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 20), (3, 20)]) - .with_candidates(vec![(1, 30), (3, 20)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10)]) - .build() - .execute_with(|| { - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 3)); - assert_noop!( - Stake::leave_nominators(Origin::signed(2), 2), - Error::::NominatorAlreadyLeaving - ); - }); -} - -#[test] -fn cannot_leave_nominators_if_already_leaving() { +fn cannot_execute_leave_delegators_before_delay() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::leave_nominators(Origin::signed(2), 1)); + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); assert_noop!( - Stake::leave_nominators(Origin::signed(2), 1), - Error::::NominatorAlreadyLeaving - ); - }); -} - -#[test] -fn cannot_leave_nominators_if_not_nominator() { - ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 10)]) - .with_candidates(vec![(1, 30)]) - .build() - .execute_with(|| { - assert_noop!( - Stake::leave_nominators(Origin::signed(2), 1), - Error::::NominatorDNE + ParachainStaking::execute_leave_delegators(Origin::signed(2), 2, 1), + Error::::DelegatorCannotLeaveYet ); + // can execute after delay + roll_to(10); + assert_ok!(ParachainStaking::execute_leave_delegators( + Origin::signed(2), + 2, + 1 + )); }); } #[test] -fn insufficient_leave_nominators_weight_hint_fails() { +fn insufficient_execute_leave_delegators_weight_hint_fails() { ExtBuilder::default() .with_balances(vec![(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20)]) .with_candidates(vec![(1, 20)]) - .with_nominations(vec![(3, 1, 10), (4, 1, 10), (5, 1, 10), (6, 1, 10)]) + .with_delegations(vec![(3, 1, 10), (4, 1, 10), (5, 1, 10), (6, 1, 10)]) .build() .execute_with(|| { + for i in 3..7 { + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + i + ))); + } + roll_to(10); for i in 3..7 { assert_noop!( - Stake::leave_nominators(Origin::signed(i), 0u32), - Error::::TooLowNominationCountToLeaveNominators + ParachainStaking::execute_leave_delegators(Origin::signed(i), i, 0), + Error::::TooLowDelegationCountToLeaveDelegators ); } }); } #[test] -fn sufficient_leave_nominators_weight_hint_succeeds() { +fn sufficient_execute_leave_delegators_weight_hint_succeeds() { ExtBuilder::default() .with_balances(vec![(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20)]) .with_candidates(vec![(1, 20)]) - .with_nominations(vec![(3, 1, 10), (4, 1, 10), (5, 1, 10), (6, 1, 10)]) + .with_delegations(vec![(3, 1, 10), (4, 1, 10), (5, 1, 10), (6, 1, 10)]) .build() .execute_with(|| { for i in 3..7 { - assert_ok!(Stake::leave_nominators(Origin::signed(i), 1u32),); + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + i + ))); + } + roll_to(10); + for i in 3..7 { + assert_ok!(ParachainStaking::execute_leave_delegators( + Origin::signed(i), + i, + 1 + )); } }); } -// REVOKE_NOMINATION +// CANCEL LEAVE DELEGATORS #[test] -fn revoke_nomination_event_emits_exit_scheduled_if_no_nominations_left() { - // last nomination is revocation +fn cancel_leave_delegators_emits_correct_event() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - roll_to(1); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::NominatorExitScheduled(1, 2, 3)) - ); - roll_to(10); - assert!(events().contains(&Event::NominatorLeftCollator(2, 1, 10, 30))); - assert!(events().contains(&Event::NominatorLeft(2, 10))); + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); + assert_ok!(ParachainStaking::cancel_leave_delegators(Origin::signed(2))); + assert_last_event!(MetaEvent::ParachainStaking(Event::DelegatorExitCancelled( + 2 + ))); }); } #[test] -fn revoke_nomination_event_emits_correctly() { +fn cancel_leave_delegators_updates_delegator_state() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 20), (3, 30)]) - .with_candidates(vec![(1, 30), (3, 30)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10)]) + .with_balances(vec![(1, 30), (2, 10)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - roll_to(1); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::NominationRevocationScheduled(1, 2, 1, 3)) - ); - roll_to(10); - assert!(events().contains(&Event::NominatorLeftCollator(2, 1, 10, 30))); + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); + assert_ok!(ParachainStaking::cancel_leave_delegators(Origin::signed(2))); + let delegator = + ParachainStaking::delegator_state(&2).expect("just cancelled exit so exists"); + assert!(delegator.is_active()); }); } +// SCHEDULE REVOKE DELEGATION + #[test] -fn revoke_nomination_unreserves_balance() { +fn revoke_delegation_event_emits_correctly() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 10)]) - .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_balances(vec![(1, 30), (2, 20), (3, 30)]) + .with_candidates(vec![(1, 30), (3, 30)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10)]) .build() .execute_with(|| { - roll_to(1); - assert_eq!(Balances::reserved_balance(&2), 10); - assert_eq!(Balances::free_balance(&2), 0); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + assert_last_event!(MetaEvent::ParachainStaking( + Event::DelegationRevocationScheduled(1, 2, 1, 3,) + )); roll_to(10); - assert_eq!(Balances::reserved_balance(&2), 0); - assert_eq!(Balances::free_balance(&2), 10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert_event_emitted!(Event::DelegatorLeftCandidate(2, 1, 10, 30)); }); } #[test] -fn revoke_nomination_adds_revocation_to_nominator_state() { +fn can_revoke_delegation_if_revoking_another_delegation() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 20), (3, 20)]) .with_candidates(vec![(1, 30), (3, 20)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10)]) .build() .execute_with(|| { - assert!(Stake::nominator_state2(2) - .expect("exists") - .revocations - .0 - .is_empty()); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - assert_eq!( - Stake::nominator_state2(2).expect("exists").revocations.0[0], + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), 1 - ); + )); + // this is an exit implicitly because last delegation revoked + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 3 + )); }); } #[test] -fn revoke_nomination_removes_revocation_from_nominator_state_upon_execution() { +fn can_revoke_if_leaving() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 20), (3, 20)]) .with_candidates(vec![(1, 30), (3, 20)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10)]) .build() .execute_with(|| { - roll_to(1); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - roll_to(10); - assert!(Stake::nominator_state2(2) - .expect("exists") - .revocations - .0 - .is_empty()); + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 3 + )); }); } #[test] -fn revoke_nomination_decreases_total_staked() { +fn cannot_revoke_delegation_if_not_delegator() { + ExtBuilder::default().build().execute_with(|| { + assert_noop!( + ParachainStaking::schedule_revoke_delegation(Origin::signed(2), 1), + Error::::DelegatorDNE + ); + }); +} + +#[test] +fn cannot_revoke_delegation_that_dne() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - roll_to(1); - assert_eq!(Stake::total(), 40); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - roll_to(10); - assert_eq!(Stake::total(), 30); + assert_noop!( + ParachainStaking::schedule_revoke_delegation(Origin::signed(2), 3), + Error::::DelegationDNE + ); }); } #[test] -fn revoke_nomination_for_last_nomination_removes_nominator_state() { +// See `cannot_execute_revoke_delegation_below_min_delegator_stake` for where the "must be above +// MinDelegatorStk" rule is now enforced. +fn can_schedule_revoke_delegation_below_min_delegator_stake() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 10)]) - .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_balances(vec![(1, 20), (2, 8), (3, 20)]) + .with_candidates(vec![(1, 20), (3, 20)]) + .with_delegations(vec![(2, 1, 5), (2, 3, 3)]) .build() .execute_with(|| { - roll_to(1); - assert!(Stake::nominator_state2(2).is_some()); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - roll_to(10); - assert!(Stake::nominator_state2(2).is_none()); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); }); } +// DELEGATOR BOND MORE + #[test] -fn revoke_nomination_removes_nomination_from_candidate_state() { +fn delegator_bond_more_reserves_balance() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 10)]) + .with_balances(vec![(1, 30), (2, 15)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - roll_to(1); - assert_eq!( - Stake::collator_state2(1) - .expect("exists") - .nominators - .0 - .len(), - 1usize - ); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - roll_to(10); - assert!(Stake::collator_state2(1) - .expect("exists") - .nominators - .0 - .is_empty()); + assert_eq!(Balances::reserved_balance(&2), 10); + assert_eq!(Balances::free_balance(&2), 5); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(2), + 1, + 5 + )); + assert_eq!(Balances::reserved_balance(&2), 15); + assert_eq!(Balances::free_balance(&2), 0); }); } #[test] -fn can_revoke_nomination_if_revoking_another_nomination() { +fn delegator_bond_more_increases_total_staked() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 20), (3, 20)]) - .with_candidates(vec![(1, 30), (3, 20)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10)]) + .with_balances(vec![(1, 30), (2, 15)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 3)); + assert_eq!(ParachainStaking::total(), 40); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(2), + 1, + 5 + )); + assert_eq!(ParachainStaking::total(), 45); }); } #[test] -fn cannot_revoke_if_leaving() { +fn delegator_bond_more_updates_delegator_state() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 20), (3, 20)]) + .with_balances(vec![(1, 30), (2, 15)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::leave_nominators(Origin::signed(2), 2)); - assert_noop!( - Stake::revoke_nomination(Origin::signed(2), 3), - Error::::CannotActBecauseLeaving + assert_eq!( + ParachainStaking::delegator_state(2).expect("exists").total, + 10 + ); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(2), + 1, + 5 + )); + assert_eq!( + ParachainStaking::delegator_state(2).expect("exists").total, + 15 ); }); } #[test] -fn cannot_revoke_nomination_if_not_nominator() { - ExtBuilder::default().build().execute_with(|| { - assert_noop!( - Stake::revoke_nomination(Origin::signed(2), 1), - Error::::NominatorDNE - ); - }); +fn delegator_bond_more_updates_candidate_state_top_delegations() { + ExtBuilder::default() + .with_balances(vec![(1, 30), (2, 15)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 10)]) + .build() + .execute_with(|| { + assert_eq!( + ParachainStaking::top_delegations(1).unwrap().delegations[0].owner, + 2 + ); + assert_eq!( + ParachainStaking::top_delegations(1).unwrap().delegations[0].amount, + 10 + ); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(2), + 1, + 5 + )); + assert_eq!( + ParachainStaking::top_delegations(1).unwrap().delegations[0].owner, + 2 + ); + assert_eq!( + ParachainStaking::top_delegations(1).unwrap().delegations[0].amount, + 15 + ); + }); } #[test] -fn cannot_revoke_nomination_that_dne() { +fn delegator_bond_more_updates_candidate_state_bottom_delegations() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 10)]) + .with_balances(vec![(1, 30), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![ + (2, 1, 10), + (3, 1, 20), + (4, 1, 20), + (5, 1, 20), + (6, 1, 20), + ]) .build() .execute_with(|| { - assert_noop!( - Stake::revoke_nomination(Origin::signed(2), 3), - Error::::NominationDNE + assert_eq!( + ParachainStaking::bottom_delegations(1) + .expect("exists") + .delegations[0] + .owner, + 2 + ); + assert_eq!( + ParachainStaking::bottom_delegations(1) + .expect("exists") + .delegations[0] + .amount, + 10 + ); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(2), + 1, + 5 + )); + assert_last_event!(MetaEvent::ParachainStaking(Event::DelegationIncreased( + 2, 1, 5, false + ))); + assert_eq!( + ParachainStaking::bottom_delegations(1) + .expect("exists") + .delegations[0] + .owner, + 2 + ); + assert_eq!( + ParachainStaking::bottom_delegations(1) + .expect("exists") + .delegations[0] + .amount, + 15 ); }); } #[test] -fn cannot_revoke_nomination_leaving_nominator_below_min_nominator_stake() { +fn delegator_bond_more_increases_total() { ExtBuilder::default() - .with_balances(vec![(1, 20), (2, 8), (3, 20)]) - .with_candidates(vec![(1, 20), (3, 20)]) - .with_nominations(vec![(2, 1, 5), (2, 3, 3)]) + .with_balances(vec![(1, 30), (2, 15)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_noop!( - Stake::revoke_nomination(Origin::signed(2), 1), - Error::::NomBondBelowMin - ); + assert_eq!(ParachainStaking::total(), 40); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(2), + 1, + 5 + )); + assert_eq!(ParachainStaking::total(), 45); }); } #[test] -fn revoke_nomination_after_leave_candidates_executes_during_leave_candidates() { +fn can_delegator_bond_more_for_leaving_candidate() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 10)]) + .with_balances(vec![(1, 30), (2, 15)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - roll_to(1); - assert_ok!(Stake::leave_candidates(Origin::signed(1), 1)); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::NominatorExitScheduled(1, 2, 3)) - ); - roll_to(10); - assert!(!Stake::is_nominator(&2)); - assert_eq!(Balances::reserved_balance(&2), 0); - assert_eq!(Balances::free_balance(&2), 10); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1 + )); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(2), + 1, + 5 + )); }); } +// DELEGATOR BOND LESS + #[test] -fn revoke_nomination_before_leave_candidates_executes_during_leave_candidates() { +fn delegator_bond_less_event_emits_correctly() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - roll_to(1); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::NominatorExitScheduled(1, 2, 3)) - ); - assert_ok!(Stake::leave_candidates(Origin::signed(1), 1)); - roll_to(10); - assert!(!Stake::is_nominator(&2)); - assert_eq!(Balances::reserved_balance(&2), 0); - assert_eq!(Balances::free_balance(&2), 10); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 1, + 5 + )); + assert_last_event!(MetaEvent::ParachainStaking( + Event::DelegationDecreaseScheduled(2, 1, 5, 3,) + )); }); } #[test] -fn nominator_bond_more_after_revoke_nomination_does_not_effect_exit() { +fn delegator_bond_less_updates_delegator_state() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 30), (3, 30)]) - .with_candidates(vec![(1, 30), (3, 30)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10)]) - .build() - .execute_with(|| { - roll_to(1); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::NominationRevocationScheduled(1, 2, 1, 3)) - ); - assert_noop!( - Stake::nominator_bond_more(Origin::signed(2), 1, 10), - Error::::CannotActBecauseRevoking - ); - assert_ok!(Stake::nominator_bond_more(Origin::signed(2), 3, 10)); - roll_to(10); - assert!(Stake::is_nominator(&2)); - assert_eq!(Balances::reserved_balance(&2), 20); - assert_eq!(Balances::free_balance(&2), 10); - }); -} - -#[test] -fn nominator_bond_less_after_revoke_nomination_does_not_effect_exit() { - ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 30), (3, 30)]) - .with_candidates(vec![(1, 30), (3, 30)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10)]) - .build() - .execute_with(|| { - roll_to(1); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::NominationRevocationScheduled(1, 2, 1, 3)) - ); - assert_noop!( - Stake::nominator_bond_less(Origin::signed(2), 1, 2), - Error::::CannotActBecauseRevoking - ); - assert_ok!(Stake::nominator_bond_less(Origin::signed(2), 3, 2)); - roll_to(10); - assert!(Stake::is_nominator(&2)); - assert_eq!(Balances::reserved_balance(&2), 8); - assert_eq!(Balances::free_balance(&2), 22); - }); -} - -// NOMINATOR BOND MORE - -#[test] -fn nominator_bond_more_event_emits_correctly() { - ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 15)]) + .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::nominator_bond_more(Origin::signed(2), 1, 5)); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 1, + 5 + )); + let state = ParachainStaking::delegator_state(&2) + .expect("just request bonded less so exists"); assert_eq!( - last_event(), - MetaEvent::Stake(Event::NominationIncreased(2, 1, 5, true)) + state.requests().get(&1), + Some(&DelegationRequest { + collator: 1, + amount: 5, + when_executable: 3, + action: DelegationChange::Decrease + }) ); }); } #[test] -fn nominator_bond_more_reserves_balance() { +fn can_delegator_bond_less_if_leaving() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 15)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_eq!(Balances::reserved_balance(&2), 10); - assert_eq!(Balances::free_balance(&2), 5); - assert_ok!(Stake::nominator_bond_more(Origin::signed(2), 1, 5)); - assert_eq!(Balances::reserved_balance(&2), 15); - assert_eq!(Balances::free_balance(&2), 0); + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 1, + 1 + )); }); } #[test] -fn nominator_bond_more_increases_total_staked() { +fn cannot_delegator_bond_less_if_revoking() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 15)]) - .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_balances(vec![(1, 30), (2, 25), (3, 20)]) + .with_candidates(vec![(1, 30), (3, 20)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10)]) .build() .execute_with(|| { - assert_eq!(Stake::total(), 40); - assert_ok!(Stake::nominator_bond_more(Origin::signed(2), 1, 5)); - assert_eq!(Stake::total(), 45); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + assert_noop!( + ParachainStaking::schedule_delegator_bond_less(Origin::signed(2), 1, 1), + Error::::PendingDelegationRequestAlreadyExists + ); }); } #[test] -fn nominator_bond_more_updates_nominator_state() { - ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 15)]) - .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) - .build() - .execute_with(|| { - assert_eq!(Stake::nominator_state2(2).expect("exists").total, 10); - assert_eq!( - Stake::nominator_state2(2).expect("exists").nominations.0[0], - Bond { - owner: 1, - amount: 10 - } - ); - assert_ok!(Stake::nominator_bond_more(Origin::signed(2), 1, 5)); - assert_eq!(Stake::nominator_state2(2).expect("exists").total, 15); - assert_eq!( - Stake::nominator_state2(2).expect("exists").nominations.0[0], - Bond { - owner: 1, - amount: 15 - } - ); - }); +fn cannot_delegator_bond_less_if_not_delegator() { + ExtBuilder::default().build().execute_with(|| { + assert_noop!( + ParachainStaking::schedule_delegator_bond_less(Origin::signed(2), 1, 5), + Error::::DelegatorDNE + ); + }); } #[test] -fn nominator_bond_more_updates_candidate_state_top_nominators() { +fn cannot_delegator_bond_less_if_candidate_dne() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 15)]) + .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_eq!( - Stake::collator_state2(1).expect("exists").top_nominators[0], - Bond { - owner: 2, - amount: 10 - } - ); - assert_ok!(Stake::nominator_bond_more(Origin::signed(2), 1, 5)); - assert_eq!( - Stake::collator_state2(1).expect("exists").top_nominators[0], - Bond { - owner: 2, - amount: 15 - } + assert_noop!( + ParachainStaking::schedule_delegator_bond_less(Origin::signed(2), 3, 5), + Error::::DelegationDNE ); }); } #[test] -fn nominator_bond_more_updates_candidate_state_bottom_nominators() { +fn cannot_delegator_bond_less_if_delegation_dne() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20)]) - .with_candidates(vec![(1, 30)]) - .with_nominations(vec![ - (2, 1, 10), - (3, 1, 20), - (4, 1, 20), - (5, 1, 20), - (6, 1, 20), - ]) + .with_balances(vec![(1, 30), (2, 10), (3, 30)]) + .with_candidates(vec![(1, 30), (3, 30)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_eq!( - Stake::collator_state2(1).expect("exists").bottom_nominators[0], - Bond { - owner: 2, - amount: 10 - } - ); - assert_ok!(Stake::nominator_bond_more(Origin::signed(2), 1, 5)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::NominationIncreased(2, 1, 5, false)) - ); - assert_eq!( - Stake::collator_state2(1).expect("exists").bottom_nominators[0], - Bond { - owner: 2, - amount: 15 - } + assert_noop!( + ParachainStaking::schedule_delegator_bond_less(Origin::signed(2), 3, 5), + Error::::DelegationDNE ); }); } #[test] -fn nominator_bond_more_increases_total() { +fn cannot_delegator_bond_less_below_min_collator_stk() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 15)]) + .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_eq!(Stake::total(), 40); - assert_ok!(Stake::nominator_bond_more(Origin::signed(2), 1, 5)); - assert_eq!(Stake::total(), 45); + assert_noop!( + ParachainStaking::schedule_delegator_bond_less(Origin::signed(2), 1, 6), + Error::::DelegatorBondBelowMin + ); }); } #[test] -fn cannot_nominator_bond_more_if_leaving() { +fn cannot_delegator_bond_less_more_than_total_delegation() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 15)]) + .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::leave_nominators(Origin::signed(2), 1)); assert_noop!( - Stake::nominator_bond_more(Origin::signed(2), 1, 5), - Error::::CannotActBecauseLeaving + ParachainStaking::schedule_delegator_bond_less(Origin::signed(2), 1, 11), + Error::::DelegatorBondBelowMin ); }); } #[test] -fn cannot_nominator_bond_more_if_revoking() { +fn cannot_delegator_bond_less_below_min_delegation() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 25), (3, 20)]) - .with_candidates(vec![(1, 30), (3, 20)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10)]) + .with_balances(vec![(1, 30), (2, 20), (3, 30)]) + .with_candidates(vec![(1, 30), (3, 30)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); assert_noop!( - Stake::nominator_bond_more(Origin::signed(2), 1, 5), - Error::::CannotActBecauseRevoking + ParachainStaking::schedule_delegator_bond_less(Origin::signed(2), 1, 8), + Error::::DelegationBelowMin ); }); } -#[test] -fn cannot_nominator_bond_more_if_not_nominator() { - ExtBuilder::default().build().execute_with(|| { - assert_noop!( - Stake::nominator_bond_more(Origin::signed(2), 1, 5), - Error::::NominatorDNE - ); - }); -} +// EXECUTE PENDING DELEGATION REQUEST + +// 1. REVOKE DELEGATION #[test] -fn cannot_nominator_bond_more_if_candidate_dne() { +fn execute_revoke_delegation_emits_exit_event_if_exit_happens() { + // last delegation is revocation ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_noop!( - Stake::nominator_bond_more(Origin::signed(2), 3, 5), - Error::::CandidateDNE - ); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert_event_emitted!(Event::DelegatorLeftCandidate(2, 1, 10, 30)); + assert_event_emitted!(Event::DelegatorLeft(2, 10)); }); } #[test] -fn cannot_nominator_bond_more_if_nomination_dne() { +fn cannot_execute_revoke_delegation_below_min_delegator_stake() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 10), (3, 30)]) - .with_candidates(vec![(1, 30), (3, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_balances(vec![(1, 20), (2, 8), (3, 20)]) + .with_candidates(vec![(1, 20), (3, 20)]) + .with_delegations(vec![(2, 1, 5), (2, 3, 3)]) .build() .execute_with(|| { + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + roll_to(10); assert_noop!( - Stake::nominator_bond_more(Origin::signed(2), 3, 5), - Error::::NominationDNE + ParachainStaking::execute_delegation_request(Origin::signed(2), 2, 1), + Error::::DelegatorBondBelowMin ); + // but delegator can cancel the request and request to leave instead: + assert_ok!(ParachainStaking::cancel_delegation_request( + Origin::signed(2), + 1 + )); + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 2 + ))); + roll_to(20); + assert_ok!(ParachainStaking::execute_leave_delegators( + Origin::signed(2), + 2, + 2 + )); }); } #[test] -fn cannot_nominator_bond_more_if_insufficient_balance() { +fn revoke_delegation_executes_exit_if_last_delegation() { + // last delegation is revocation ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_noop!( - Stake::nominator_bond_more(Origin::signed(2), 1, 5), - DispatchError::Module { - index: 1, - error: 2, - message: Some("InsufficientBalance") - } - ); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert_event_emitted!(Event::DelegatorLeftCandidate(2, 1, 10, 30)); + assert_event_emitted!(Event::DelegatorLeft(2, 10)); }); } -// NOMINATOR BOND LESS - #[test] -fn nominator_bond_less_event_emits_correctly() { +fn execute_revoke_delegation_emits_correct_event() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 10)]) - .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_balances(vec![(1, 30), (2, 20), (3, 30)]) + .with_candidates(vec![(1, 30), (3, 30)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::nominator_bond_less(Origin::signed(2), 1, 5)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::NominationDecreased(2, 1, 5, true)) - ); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert_event_emitted!(Event::DelegatorLeftCandidate(2, 1, 10, 30)); }); } #[test] -fn nominator_bond_less_unreserves_balance() { +fn execute_revoke_delegation_unreserves_balance() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { assert_eq!(Balances::reserved_balance(&2), 10); assert_eq!(Balances::free_balance(&2), 0); - assert_ok!(Stake::nominator_bond_less(Origin::signed(2), 1, 5)); - assert_eq!(Balances::reserved_balance(&2), 5); - assert_eq!(Balances::free_balance(&2), 5); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert_eq!(Balances::reserved_balance(&2), 0); + assert_eq!(Balances::free_balance(&2), 10); }); } #[test] -fn nominator_bond_less_decreases_total_staked() { +fn execute_revoke_delegation_adds_revocation_to_delegator_state() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 10)]) - .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_balances(vec![(1, 30), (2, 20), (3, 20)]) + .with_candidates(vec![(1, 30), (3, 20)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10)]) .build() .execute_with(|| { - assert_eq!(Stake::total(), 40); - assert_ok!(Stake::nominator_bond_less(Origin::signed(2), 1, 5)); - assert_eq!(Stake::total(), 35); + assert!(ParachainStaking::delegator_state(2) + .expect("exists") + .requests + .requests + .get(&1) + .is_none()); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + assert!(ParachainStaking::delegator_state(2) + .expect("exists") + .requests + .requests + .get(&1) + .is_some()); }); } #[test] -fn nominator_bond_less_updates_nominator_state() { +fn execute_revoke_delegation_removes_revocation_from_delegator_state_upon_execution() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 15)]) - .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_balances(vec![(1, 30), (2, 20), (3, 20)]) + .with_candidates(vec![(1, 30), (3, 20)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10)]) .build() .execute_with(|| { - assert_eq!(Stake::nominator_state2(2).expect("exists").total, 10); - assert_eq!( - Stake::nominator_state2(2).expect("exists").nominations.0[0], - Bond { - owner: 1, - amount: 10 - } - ); - assert_ok!(Stake::nominator_bond_less(Origin::signed(2), 1, 5)); - assert_eq!(Stake::nominator_state2(2).expect("exists").total, 5); - assert_eq!( - Stake::nominator_state2(2).expect("exists").nominations.0[0], - Bond { - owner: 1, - amount: 5 - } - ); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert!(ParachainStaking::delegator_state(2) + .expect("exists") + .requests + .requests + .get(&1) + .is_none()); }); } #[test] -fn nominator_bond_less_updates_candidate_state() { +fn execute_revoke_delegation_decreases_total_staked() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 15)]) + .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_eq!( - Stake::collator_state2(1).expect("exists").top_nominators[0], - Bond { - owner: 2, - amount: 10 - } - ); - assert_ok!(Stake::nominator_bond_less(Origin::signed(2), 1, 5)); - assert_eq!( - Stake::collator_state2(1).expect("exists").top_nominators[0], - Bond { - owner: 2, - amount: 5 - } - ); + assert_eq!(ParachainStaking::total(), 40); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert_eq!(ParachainStaking::total(), 30); }); } #[test] -fn nominator_bond_less_decreases_total() { +fn execute_revoke_delegation_for_last_delegation_removes_delegator_state() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 15)]) + .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_eq!(Stake::total(), 40); - assert_ok!(Stake::nominator_bond_less(Origin::signed(2), 1, 5)); - assert_eq!(Stake::total(), 35); + assert!(ParachainStaking::delegator_state(2).is_some()); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + roll_to(10); + // this will be confusing for people + // if status is leaving, then execute_delegation_request works if last delegation + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert!(ParachainStaking::delegator_state(2).is_none()); }); } #[test] -fn cannot_nominator_bond_less_if_leaving() { +fn execute_revoke_delegation_removes_delegation_from_candidate_state() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 15)]) + .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::leave_nominators(Origin::signed(2), 1)); - assert_noop!( - Stake::nominator_bond_less(Origin::signed(2), 1, 1), - Error::::CannotActBecauseLeaving + assert_eq!( + ParachainStaking::candidate_info(1) + .expect("exists") + .delegation_count, + 1u32 ); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert!(ParachainStaking::candidate_info(1) + .expect("exists") + .delegation_count + .is_zero()); }); } #[test] -fn cannot_nominator_bond_less_if_revoking() { +fn can_execute_revoke_delegation_for_leaving_candidate() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 25), (3, 20)]) - .with_candidates(vec![(1, 30), (3, 20)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10)]) + .with_balances(vec![(1, 30), (2, 10)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); - assert_noop!( - Stake::nominator_bond_less(Origin::signed(2), 1, 1), - Error::::CannotActBecauseRevoking - ); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1 + )); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + roll_to(10); + // can execute delegation request for leaving candidate + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); }); } #[test] -fn cannot_nominator_bond_less_if_not_nominator() { - ExtBuilder::default().build().execute_with(|| { - assert_noop!( - Stake::nominator_bond_less(Origin::signed(2), 1, 5), - Error::::NominatorDNE - ); - }); -} - -#[test] -fn cannot_nominator_bond_less_if_candidate_dne() { +fn can_execute_leave_candidates_if_revoking_candidate() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_noop!( - Stake::nominator_bond_less(Origin::signed(2), 3, 5), - Error::::CandidateDNE - ); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1 + )); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + roll_to(10); + // revocation executes during execute leave candidates (callable by anyone) + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(1), + 1, + 1 + )); + assert!(!ParachainStaking::is_delegator(&2)); + assert_eq!(Balances::reserved_balance(&2), 0); + assert_eq!(Balances::free_balance(&2), 10); }); } #[test] -fn cannot_nominator_bond_less_if_nomination_dne() { +fn delegator_bond_more_after_revoke_delegation_does_not_effect_exit() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 10), (3, 30)]) + .with_balances(vec![(1, 30), (2, 30), (3, 30)]) + .with_candidates(vec![(1, 30), (3, 30)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(2), + 3, + 10 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert!(ParachainStaking::is_delegator(&2)); + assert_eq!(Balances::reserved_balance(&2), 20); + assert_eq!(Balances::free_balance(&2), 10); + }); +} + +#[test] +fn delegator_bond_less_after_revoke_delegation_does_not_effect_exit() { + ExtBuilder::default() + .with_balances(vec![(1, 30), (2, 30), (3, 30)]) .with_candidates(vec![(1, 30), (3, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10)]) .build() .execute_with(|| { + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + assert_last_event!(MetaEvent::ParachainStaking( + Event::DelegationRevocationScheduled(1, 2, 1, 3,) + )); assert_noop!( - Stake::nominator_bond_less(Origin::signed(2), 3, 5), - Error::::NominationDNE + ParachainStaking::schedule_delegator_bond_less(Origin::signed(2), 1, 2), + Error::::PendingDelegationRequestAlreadyExists ); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 3, + 2 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 3 + )); + assert_last_event!(MetaEvent::ParachainStaking(Event::DelegationDecreased( + 2, 3, 2, true + ))); + assert!(ParachainStaking::is_delegator(&2)); + assert_eq!(Balances::reserved_balance(&2), 8); + assert_eq!(Balances::free_balance(&2), 22); }); } +// 2. EXECUTE BOND LESS + #[test] -fn cannot_nominator_bond_less_below_min_collator_stk() { +fn execute_delegator_bond_less_unreserves_balance() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_noop!( - Stake::nominator_bond_less(Origin::signed(2), 1, 6), - Error::::NomBondBelowMin - ); + assert_eq!(Balances::reserved_balance(&2), 10); + assert_eq!(Balances::free_balance(&2), 0); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 1, + 5 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert_eq!(Balances::reserved_balance(&2), 5); + assert_eq!(Balances::free_balance(&2), 5); }); } #[test] -fn cannot_nominator_bond_less_more_than_total_nomination() { +fn execute_delegator_bond_less_decreases_total_staked() { ExtBuilder::default() .with_balances(vec![(1, 30), (2, 10)]) .with_candidates(vec![(1, 30)]) - .with_nominations(vec![(2, 1, 10)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_noop!( - Stake::nominator_bond_less(Origin::signed(2), 1, 11), - Error::::NomBondBelowMin + assert_eq!(ParachainStaking::total(), 40); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 1, + 5 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert_eq!(ParachainStaking::total(), 35); + }); +} + +#[test] +fn execute_delegator_bond_less_updates_delegator_state() { + ExtBuilder::default() + .with_balances(vec![(1, 30), (2, 15)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 10)]) + .build() + .execute_with(|| { + assert_eq!( + ParachainStaking::delegator_state(2).expect("exists").total, + 10 + ); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 1, + 5 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert_eq!( + ParachainStaking::delegator_state(2).expect("exists").total, + 5 ); }); } #[test] -fn cannot_nominator_bond_less_below_min_nomination() { +fn execute_delegator_bond_less_updates_candidate_state() { ExtBuilder::default() - .with_balances(vec![(1, 30), (2, 20), (3, 30)]) - .with_candidates(vec![(1, 30), (3, 30)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10)]) + .with_balances(vec![(1, 30), (2, 15)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 10)]) .build() .execute_with(|| { - assert_noop!( - Stake::nominator_bond_less(Origin::signed(2), 1, 8), - Error::::NominationBelowMin + assert_eq!( + ParachainStaking::top_delegations(1).unwrap().delegations[0].owner, + 2 + ); + assert_eq!( + ParachainStaking::top_delegations(1).unwrap().delegations[0].amount, + 10 + ); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 1, + 5 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert_eq!( + ParachainStaking::top_delegations(1).unwrap().delegations[0].owner, + 2 ); + assert_eq!( + ParachainStaking::top_delegations(1).unwrap().delegations[0].amount, + 5 + ); + }); +} + +#[test] +fn execute_delegator_bond_less_decreases_total() { + ExtBuilder::default() + .with_balances(vec![(1, 30), (2, 15)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 10)]) + .build() + .execute_with(|| { + assert_eq!(ParachainStaking::total(), 40); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 1, + 5 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + assert_eq!(ParachainStaking::total(), 35); }); } #[test] -fn nominator_bond_less_updates_just_bottom_nominations() { +fn execute_delegator_bond_less_updates_just_bottom_delegations() { ExtBuilder::default() .with_balances(vec![(1, 20), (2, 10), (3, 11), (4, 12), (5, 14), (6, 15)]) .with_candidates(vec![(1, 20)]) - .with_nominations(vec![ + .with_delegations(vec![ (2, 1, 10), (3, 1, 11), (4, 1, 12), @@ -2519,17 +3228,35 @@ fn nominator_bond_less_updates_just_bottom_nominations() { ]) .build() .execute_with(|| { - let pre_call_collator_state = - Stake::collator_state2(&1).expect("nominated by all so exists"); - assert_ok!(Stake::nominator_bond_less(Origin::signed(2), 1, 2)); - let post_call_collator_state = - Stake::collator_state2(&1).expect("nominated by all so exists"); + let pre_call_candidate_info = + ParachainStaking::candidate_info(&1).expect("delegated by all so exists"); + let pre_call_top_delegations = + ParachainStaking::top_delegations(&1).expect("delegated by all so exists"); + let pre_call_bottom_delegations = + ParachainStaking::bottom_delegations(&1).expect("delegated by all so exists"); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 1, + 2 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + let post_call_candidate_info = + ParachainStaking::candidate_info(&1).expect("delegated by all so exists"); + let post_call_top_delegations = + ParachainStaking::top_delegations(&1).expect("delegated by all so exists"); + let post_call_bottom_delegations = + ParachainStaking::bottom_delegations(&1).expect("delegated by all so exists"); let mut not_equal = false; - for Bond { owner, amount } in pre_call_collator_state.bottom_nominators { + for Bond { owner, amount } in pre_call_bottom_delegations.delegations { for Bond { owner: post_owner, amount: post_amount, - } in &post_call_collator_state.bottom_nominators + } in &post_call_bottom_delegations.delegations { if &owner == post_owner { if &amount != post_amount { @@ -2541,11 +3268,11 @@ fn nominator_bond_less_updates_just_bottom_nominations() { } assert!(not_equal); let mut equal = true; - for Bond { owner, amount } in pre_call_collator_state.top_nominators { + for Bond { owner, amount } in pre_call_top_delegations.delegations { for Bond { owner: post_owner, amount: post_amount, - } in &post_call_collator_state.top_nominators + } in &post_call_top_delegations.delegations { if &owner == post_owner { if &amount != post_amount { @@ -2557,22 +3284,18 @@ fn nominator_bond_less_updates_just_bottom_nominations() { } assert!(equal); assert_eq!( - pre_call_collator_state.total_backing - 2, - post_call_collator_state.total_backing - ); - assert_eq!( - pre_call_collator_state.total_counted, - post_call_collator_state.total_counted + pre_call_candidate_info.total_counted, + post_call_candidate_info.total_counted ); }); } #[test] -fn nominator_bond_less_does_not_delete_bottom_nominations() { +fn execute_delegator_bond_less_does_not_delete_bottom_delegations() { ExtBuilder::default() .with_balances(vec![(1, 20), (2, 10), (3, 11), (4, 12), (5, 14), (6, 15)]) .with_candidates(vec![(1, 20)]) - .with_nominations(vec![ + .with_delegations(vec![ (2, 1, 10), (3, 1, 11), (4, 1, 12), @@ -2581,17 +3304,35 @@ fn nominator_bond_less_does_not_delete_bottom_nominations() { ]) .build() .execute_with(|| { - let pre_call_collator_state = - Stake::collator_state2(&1).expect("nominated by all so exists"); - assert_ok!(Stake::nominator_bond_less(Origin::signed(6), 1, 4)); - let post_call_collator_state = - Stake::collator_state2(&1).expect("nominated by all so exists"); + let pre_call_candidate_info = + ParachainStaking::candidate_info(&1).expect("delegated by all so exists"); + let pre_call_top_delegations = + ParachainStaking::top_delegations(&1).expect("delegated by all so exists"); + let pre_call_bottom_delegations = + ParachainStaking::bottom_delegations(&1).expect("delegated by all so exists"); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(6), + 1, + 4 + )); + roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(6), + 6, + 1 + )); + let post_call_candidate_info = + ParachainStaking::candidate_info(&1).expect("delegated by all so exists"); + let post_call_top_delegations = + ParachainStaking::top_delegations(&1).expect("delegated by all so exists"); + let post_call_bottom_delegations = + ParachainStaking::bottom_delegations(&1).expect("delegated by all so exists"); let mut equal = true; - for Bond { owner, amount } in pre_call_collator_state.bottom_nominators { + for Bond { owner, amount } in pre_call_bottom_delegations.delegations { for Bond { owner: post_owner, amount: post_amount, - } in &post_call_collator_state.bottom_nominators + } in &post_call_bottom_delegations.delegations { if &owner == post_owner { if &amount != post_amount { @@ -2603,11 +3344,11 @@ fn nominator_bond_less_does_not_delete_bottom_nominations() { } assert!(equal); let mut not_equal = false; - for Bond { owner, amount } in pre_call_collator_state.top_nominators { + for Bond { owner, amount } in pre_call_top_delegations.delegations { for Bond { owner: post_owner, amount: post_amount, - } in &post_call_collator_state.top_nominators + } in &post_call_top_delegations.delegations { if &owner == post_owner { if &amount != post_amount { @@ -2619,55 +3360,245 @@ fn nominator_bond_less_does_not_delete_bottom_nominations() { } assert!(not_equal); assert_eq!( - pre_call_collator_state.total_backing - 4, - post_call_collator_state.total_backing + pre_call_candidate_info.total_counted - 4, + post_call_candidate_info.total_counted + ); + }); +} + +#[test] +fn can_execute_delegator_bond_less_for_leaving_candidate() { + ExtBuilder::default() + .with_balances(vec![(1, 30), (2, 15)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 15)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(1), + 1 + )); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 1, + 5 + )); + roll_to(10); + // can execute bond more delegation request for leaving candidate + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); + }); +} + +// CANCEL PENDING DELEGATION REQUEST +// 1. CANCEL REVOKE DELEGATION + +#[test] +fn cancel_revoke_delegation_emits_correct_event() { + ExtBuilder::default() + .with_balances(vec![(1, 30), (2, 10)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 10)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + assert_ok!(ParachainStaking::cancel_delegation_request( + Origin::signed(2), + 1 + )); + assert_last_event!(MetaEvent::ParachainStaking( + Event::CancelledDelegationRequest( + 2, + DelegationRequest { + collator: 1, + amount: 10, + when_executable: 3, + action: DelegationChange::Revoke, + }, + ) + )); + }); +} + +#[test] +fn cancel_revoke_delegation_updates_delegator_state() { + ExtBuilder::default() + .with_balances(vec![(1, 30), (2, 10)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 10)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); + let state = ParachainStaking::delegator_state(&2).unwrap(); + assert_eq!( + state.requests().get(&1), + Some(&DelegationRequest { + collator: 1, + amount: 10, + when_executable: 3, + action: DelegationChange::Revoke, + }) ); + assert_eq!(state.requests.less_total, 10); + assert_ok!(ParachainStaking::cancel_delegation_request( + Origin::signed(2), + 1 + )); + let state = ParachainStaking::delegator_state(&2).unwrap(); + assert!(state.requests().get(&1).is_none()); + assert_eq!(state.requests.less_total, 0); + }); +} + +// 2. CANCEL DELEGATOR BOND LESS + +#[test] +fn cancel_delegator_bond_less_correct_event() { + ExtBuilder::default() + .with_balances(vec![(1, 30), (2, 15)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 15)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 1, + 5 + )); + assert_ok!(ParachainStaking::cancel_delegation_request( + Origin::signed(2), + 1 + )); + assert_last_event!(MetaEvent::ParachainStaking( + Event::CancelledDelegationRequest( + 2, + DelegationRequest { + collator: 1, + amount: 5, + when_executable: 3, + action: DelegationChange::Decrease, + }, + ) + )); + }); +} + +#[test] +fn cancel_delegator_bond_less_updates_delegator_state() { + ExtBuilder::default() + .with_balances(vec![(1, 30), (2, 15)]) + .with_candidates(vec![(1, 30)]) + .with_delegations(vec![(2, 1, 15)]) + .build() + .execute_with(|| { + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(2), + 1, + 5 + )); + let state = ParachainStaking::delegator_state(&2).unwrap(); assert_eq!( - pre_call_collator_state.total_counted - 4, - post_call_collator_state.total_counted + state.requests().get(&1), + Some(&DelegationRequest { + collator: 1, + amount: 5, + when_executable: 3, + action: DelegationChange::Decrease, + }) ); + assert_eq!(state.requests.less_total, 5); + assert_ok!(ParachainStaking::cancel_delegation_request( + Origin::signed(2), + 1 + )); + let state = ParachainStaking::delegator_state(&2).unwrap(); + assert!(state.requests().get(&1).is_none()); + assert_eq!(state.requests.less_total, 0); }); } // ~~ PROPERTY-BASED TESTS ~~ #[test] -fn nominator_schedule_revocation_total() { +fn delegator_schedule_revocation_total() { ExtBuilder::default() .with_balances(vec![(1, 20), (2, 40), (3, 20), (4, 20), (5, 20)]) .with_candidates(vec![(1, 20), (3, 20), (4, 20), (5, 20)]) - .with_nominations(vec![(2, 1, 10), (2, 3, 10), (2, 4, 10)]) + .with_delegations(vec![(2, 1, 10), (2, 3, 10), (2, 4, 10)]) .build() .execute_with(|| { - roll_to(1); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 1)); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 1 + )); assert_eq!( - Stake::nominator_state2(2) + ParachainStaking::delegator_state(2) .expect("exists") - .scheduled_revocations_total, + .requests + .less_total, 10 ); roll_to(10); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 1 + )); assert_eq!( - Stake::nominator_state2(2) + ParachainStaking::delegator_state(2) .expect("exists") - .scheduled_revocations_total, + .requests + .less_total, 0 ); - assert_ok!(Stake::nominate(Origin::signed(2), 5, 10, 0, 2)); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 3)); - assert_ok!(Stake::revoke_nomination(Origin::signed(2), 4)); + assert_ok!(ParachainStaking::delegate(Origin::signed(2), 5, 10, 0, 2)); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 3 + )); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(2), + 4 + )); assert_eq!( - Stake::nominator_state2(2) + ParachainStaking::delegator_state(2) .expect("exists") - .scheduled_revocations_total, + .requests + .less_total, 20 ); roll_to(20); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 3 + )); + assert_eq!( + ParachainStaking::delegator_state(2) + .expect("exists") + .requests + .less_total, + 10 + ); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(2), + 2, + 4 + )); assert_eq!( - Stake::nominator_state2(2) + ParachainStaking::delegator_state(2) .expect("exists") - .scheduled_revocations_total, + .requests + .less_total, 0 ); }); @@ -2690,7 +3621,7 @@ fn parachain_bond_inflation_reserve_matches_config() { (11, 1), ]) .with_candidates(vec![(1, 20), (2, 20), (3, 20), (4, 20), (5, 10)]) - .with_nominations(vec![ + .with_delegations(vec![ (6, 1, 10), (7, 1, 10), (8, 2, 10), @@ -2702,7 +3633,10 @@ fn parachain_bond_inflation_reserve_matches_config() { assert_eq!(Balances::free_balance(&11), 1); // set parachain bond account so DefaultParachainBondReservePercent = 30% of inflation // is allocated to this account hereafter - assert_ok!(Stake::set_parachain_bond_account(Origin::root(), 11)); + assert_ok!(ParachainStaking::set_parachain_bond_account( + Origin::root(), + 11 + )); roll_to(8); // chooses top TotalSelectedCandidates (5), in order let mut expected = vec![ @@ -2714,12 +3648,12 @@ fn parachain_bond_inflation_reserve_matches_config() { Event::CollatorChosen(2, 5, 10), Event::NewRound(5, 2, 5, 140), ]; - assert_eq!(events(), expected); + assert_eq_events!(expected.clone()); assert_eq!(Balances::free_balance(&11), 1); // ~ set block author as 1 for all blocks this round set_author(2, 1, 100); roll_to(16); - // distribute total issuance to collator 1 and its nominators 6, 7, 19 + // distribute total issuance to collator 1 and its delegators 6, 7, 19 let mut new = vec![ Event::CollatorChosen(3, 1, 50), Event::CollatorChosen(3, 2, 40), @@ -2728,164 +3662,184 @@ fn parachain_bond_inflation_reserve_matches_config() { Event::CollatorChosen(3, 5, 10), Event::NewRound(10, 3, 5, 140), Event::ReservedForParachainBond(11, 15), - Event::Rewarded(1, 20), - Event::Rewarded(6, 5), - Event::Rewarded(7, 5), - Event::Rewarded(10, 5), Event::CollatorChosen(4, 1, 50), Event::CollatorChosen(4, 2, 40), Event::CollatorChosen(4, 3, 20), Event::CollatorChosen(4, 4, 20), Event::CollatorChosen(4, 5, 10), Event::NewRound(15, 4, 5, 140), + Event::Rewarded(1, 20), + Event::Rewarded(6, 5), + Event::Rewarded(7, 5), + Event::Rewarded(10, 5), ]; expected.append(&mut new); - assert_eq!(events(), expected); + assert_eq_events!(expected.clone()); assert_eq!(Balances::free_balance(&11), 16); // ~ set block author as 1 for all blocks this round set_author(3, 1, 100); set_author(4, 1, 100); set_author(5, 1, 100); - // 1. ensure nominators are paid for 2 rounds after they leave + // 1. ensure delegators are paid for 2 rounds after they leave assert_noop!( - Stake::leave_nominators(Origin::signed(66), 10), - Error::::NominatorDNE + ParachainStaking::schedule_leave_delegators(Origin::signed(66)), + Error::::DelegatorDNE ); - assert_ok!(Stake::leave_nominators(Origin::signed(6), 10)); - // fast forward to block in which nominator 6 exit executes + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 6 + ))); + // fast forward to block in which delegator 6 exit executes roll_to(25); + assert_ok!(ParachainStaking::execute_leave_delegators( + Origin::signed(6), + 6, + 10 + )); + roll_to(30); let mut new2 = vec![ - Event::NominatorExitScheduled(4, 6, 6), + Event::DelegatorExitScheduled(4, 6, 6), Event::ReservedForParachainBond(11, 16), - Event::Rewarded(1, 21), - Event::Rewarded(6, 5), - Event::Rewarded(7, 5), - Event::Rewarded(10, 5), Event::CollatorChosen(5, 1, 50), Event::CollatorChosen(5, 2, 40), Event::CollatorChosen(5, 3, 20), Event::CollatorChosen(5, 4, 20), Event::CollatorChosen(5, 5, 10), Event::NewRound(20, 5, 5, 140), + Event::Rewarded(1, 21), + Event::Rewarded(6, 5), + Event::Rewarded(7, 5), + Event::Rewarded(10, 5), Event::ReservedForParachainBond(11, 16), - Event::Rewarded(1, 22), - Event::Rewarded(6, 6), - Event::Rewarded(7, 6), - Event::Rewarded(10, 6), - Event::NominatorLeftCollator(6, 1, 10, 40), - Event::NominatorLeft(6, 10), - Event::CollatorChosen(6, 1, 40), + Event::CollatorChosen(6, 1, 50), Event::CollatorChosen(6, 2, 40), Event::CollatorChosen(6, 3, 20), Event::CollatorChosen(6, 4, 20), Event::CollatorChosen(6, 5, 10), - Event::NewRound(25, 6, 5, 130), + Event::NewRound(25, 6, 5, 140), + Event::Rewarded(1, 22), + Event::Rewarded(6, 6), + Event::Rewarded(7, 6), + Event::Rewarded(10, 6), + Event::DelegatorLeftCandidate(6, 1, 10, 40), + Event::DelegatorLeft(6, 10), + Event::ReservedForParachainBond(11, 17), + Event::CollatorChosen(7, 1, 40), + Event::CollatorChosen(7, 2, 40), + Event::CollatorChosen(7, 3, 20), + Event::CollatorChosen(7, 4, 20), + Event::CollatorChosen(7, 5, 10), + Event::NewRound(30, 7, 5, 130), + Event::Rewarded(1, 24), + Event::Rewarded(6, 6), + Event::Rewarded(7, 6), + Event::Rewarded(10, 6), ]; expected.append(&mut new2); - assert_eq!(events(), expected); - assert_eq!(Balances::free_balance(&11), 48); - assert_ok!(Stake::set_parachain_bond_reserve_percent( + assert_eq_events!(expected.clone()); + assert_eq!(Balances::free_balance(&11), 65); + assert_ok!(ParachainStaking::set_parachain_bond_reserve_percent( Origin::root(), Percent::from_percent(50) )); // 6 won't be paid for this round because they left already set_author(6, 1, 100); - roll_to(30); + roll_to(35); // keep paying 6 let mut new3 = vec![ Event::ParachainBondReservePercentSet( Percent::from_percent(30), Percent::from_percent(50), ), - Event::ReservedForParachainBond(11, 29), - Event::Rewarded(1, 19), - Event::Rewarded(6, 3), - Event::Rewarded(7, 3), - Event::Rewarded(10, 3), - Event::CollatorChosen(7, 1, 40), - Event::CollatorChosen(7, 2, 40), - Event::CollatorChosen(7, 3, 20), - Event::CollatorChosen(7, 4, 20), - Event::CollatorChosen(7, 5, 10), - Event::NewRound(30, 7, 5, 130), - ]; - expected.append(&mut new3); - assert_eq!(events(), expected); - assert_eq!(Balances::free_balance(&11), 77); - set_author(7, 1, 100); - roll_to(35); - // no more paying 6 - let mut new4 = vec![ Event::ReservedForParachainBond(11, 30), - Event::Rewarded(1, 21), - Event::Rewarded(7, 5), - Event::Rewarded(10, 5), Event::CollatorChosen(8, 1, 40), Event::CollatorChosen(8, 2, 40), Event::CollatorChosen(8, 3, 20), Event::CollatorChosen(8, 4, 20), Event::CollatorChosen(8, 5, 10), Event::NewRound(35, 8, 5, 130), + Event::Rewarded(1, 20), + Event::Rewarded(6, 4), + Event::Rewarded(7, 4), + Event::Rewarded(10, 4), ]; - expected.append(&mut new4); - assert_eq!(events(), expected); - assert_eq!(Balances::free_balance(&11), 107); - set_author(8, 1, 100); - assert_ok!(Stake::nominate(Origin::signed(8), 1, 10, 10, 10)); + expected.append(&mut new3); + assert_eq_events!(expected.clone()); + assert_eq!(Balances::free_balance(&11), 95); + set_author(7, 1, 100); roll_to(40); - // new nomination is not rewarded yet - let mut new5 = vec![ - Event::Nomination(8, 10, 1, NominatorAdded::AddedToTop { new_total: 50 }), + // no more paying 6 + let mut new4 = vec![ Event::ReservedForParachainBond(11, 32), - Event::Rewarded(1, 22), - Event::Rewarded(7, 5), - Event::Rewarded(10, 5), - Event::CollatorChosen(9, 1, 50), + Event::CollatorChosen(9, 1, 40), Event::CollatorChosen(9, 2, 40), Event::CollatorChosen(9, 3, 20), Event::CollatorChosen(9, 4, 20), Event::CollatorChosen(9, 5, 10), - Event::NewRound(40, 9, 5, 140), + Event::NewRound(40, 9, 5, 130), + Event::Rewarded(1, 22), + Event::Rewarded(7, 5), + Event::Rewarded(10, 5), ]; - expected.append(&mut new5); - assert_eq!(events(), expected); - assert_eq!(Balances::free_balance(&11), 139); - set_author(9, 1, 100); + expected.append(&mut new4); + assert_eq_events!(expected.clone()); + assert_eq!(Balances::free_balance(&11), 127); + set_author(8, 1, 100); + assert_ok!(ParachainStaking::delegate(Origin::signed(8), 1, 10, 10, 10)); roll_to(45); - // new nomination is still not rewarded yet - let mut new6 = vec![ + // new delegation is not rewarded yet + let mut new5 = vec![ + Event::Delegation(8, 10, 1, DelegatorAdded::AddedToTop { new_total: 50 }), Event::ReservedForParachainBond(11, 33), - Event::Rewarded(1, 23), - Event::Rewarded(7, 5), - Event::Rewarded(10, 5), Event::CollatorChosen(10, 1, 50), Event::CollatorChosen(10, 2, 40), Event::CollatorChosen(10, 3, 20), Event::CollatorChosen(10, 4, 20), Event::CollatorChosen(10, 5, 10), Event::NewRound(45, 10, 5, 140), + Event::Rewarded(1, 23), + Event::Rewarded(7, 5), + Event::Rewarded(10, 5), ]; - expected.append(&mut new6); - assert_eq!(events(), expected); - assert_eq!(Balances::free_balance(&11), 172); + expected.append(&mut new5); + assert_eq_events!(expected.clone()); + assert_eq!(Balances::free_balance(&11), 160); + set_author(9, 1, 100); + set_author(10, 1, 100); roll_to(50); - // new nomination is rewarded, 2 rounds after joining (`RewardPaymentDelay` is 2) - let mut new7 = vec![ + // new delegation is still not rewarded yet + let mut new6 = vec![ Event::ReservedForParachainBond(11, 35), - Event::Rewarded(1, 22), - Event::Rewarded(7, 4), - Event::Rewarded(8, 4), - Event::Rewarded(10, 4), Event::CollatorChosen(11, 1, 50), Event::CollatorChosen(11, 2, 40), Event::CollatorChosen(11, 3, 20), Event::CollatorChosen(11, 4, 20), Event::CollatorChosen(11, 5, 10), Event::NewRound(50, 11, 5, 140), + Event::Rewarded(1, 24), + Event::Rewarded(7, 5), + Event::Rewarded(10, 5), + ]; + expected.append(&mut new6); + assert_eq_events!(expected.clone()); + assert_eq!(Balances::free_balance(&11), 195); + roll_to(55); + // new delegation is rewarded, 2 rounds after joining (`RewardPaymentDelay` is 2) + let mut new7 = vec![ + Event::ReservedForParachainBond(11, 37), + Event::CollatorChosen(12, 1, 50), + Event::CollatorChosen(12, 2, 40), + Event::CollatorChosen(12, 3, 20), + Event::CollatorChosen(12, 4, 20), + Event::CollatorChosen(12, 5, 10), + Event::NewRound(55, 12, 5, 140), + Event::Rewarded(1, 24), + Event::Rewarded(7, 4), + Event::Rewarded(10, 4), + Event::Rewarded(8, 4), ]; expected.append(&mut new7); - assert_eq!(events(), expected); - assert_eq!(Balances::free_balance(&11), 207); + assert_eq_events!(expected); + assert_eq!(Balances::free_balance(&11), 232); }); } @@ -2901,7 +3855,7 @@ fn paid_collator_commission_matches_config() { (6, 100), ]) .with_candidates(vec![(1, 20)]) - .with_nominations(vec![(2, 1, 10), (3, 1, 10)]) + .with_delegations(vec![(2, 1, 10), (3, 1, 10)]) .build() .execute_with(|| { roll_to(8); @@ -2910,44 +3864,47 @@ fn paid_collator_commission_matches_config() { Event::CollatorChosen(2, 1, 40), Event::NewRound(5, 2, 1, 40), ]; - assert_eq!(events(), expected); - assert_ok!(Stake::join_candidates(Origin::signed(4), 20u128, 100u32)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::JoinedCollatorCandidates(4, 20u128, 60u128)) - ); + assert_eq_events!(expected.clone()); + assert_ok!(ParachainStaking::join_candidates( + Origin::signed(4), + 20u128, + 100u32 + )); + assert_last_event!(MetaEvent::ParachainStaking( + Event::JoinedCollatorCandidates(4, 20u128, 60u128,) + )); roll_to(9); - assert_ok!(Stake::nominate(Origin::signed(5), 4, 10, 10, 10)); - assert_ok!(Stake::nominate(Origin::signed(6), 4, 10, 10, 10)); + assert_ok!(ParachainStaking::delegate(Origin::signed(5), 4, 10, 10, 10)); + assert_ok!(ParachainStaking::delegate(Origin::signed(6), 4, 10, 10, 10)); roll_to(11); let mut new = vec![ Event::JoinedCollatorCandidates(4, 20, 60), - Event::Nomination(5, 10, 4, NominatorAdded::AddedToTop { new_total: 30 }), - Event::Nomination(6, 10, 4, NominatorAdded::AddedToTop { new_total: 40 }), + Event::Delegation(5, 10, 4, DelegatorAdded::AddedToTop { new_total: 30 }), + Event::Delegation(6, 10, 4, DelegatorAdded::AddedToTop { new_total: 40 }), Event::CollatorChosen(3, 1, 40), Event::CollatorChosen(3, 4, 40), Event::NewRound(10, 3, 2, 80), ]; expected.append(&mut new); - assert_eq!(events(), expected); + assert_eq_events!(expected.clone()); // only reward author with id 4 set_author(3, 4, 100); roll_to(21); - // 20% of 10 is commission + due_portion (4) = 2 + 4 = 6 - // all nominator payouts are 10-2 = 8 * stake_pct + // 20% of 10 is commission + due_portion (0) = 2 + 4 = 6 + // all delegator payouts are 10-2 = 8 * stake_pct let mut new2 = vec![ Event::CollatorChosen(4, 1, 40), Event::CollatorChosen(4, 4, 40), Event::NewRound(15, 4, 2, 80), - Event::Rewarded(4, 18), - Event::Rewarded(5, 6), - Event::Rewarded(6, 6), Event::CollatorChosen(5, 1, 40), Event::CollatorChosen(5, 4, 40), Event::NewRound(20, 5, 2, 80), + Event::Rewarded(4, 18), + Event::Rewarded(5, 6), + Event::Rewarded(6, 6), ]; expected.append(&mut new2); - assert_eq!(events(), expected); + assert_eq_events!(expected); }); } @@ -2966,14 +3923,22 @@ fn collator_exit_executes_after_delay() { (9, 4), ]) .with_candidates(vec![(1, 500), (2, 200)]) - .with_nominations(vec![(3, 1, 100), (4, 1, 100), (5, 2, 100), (6, 2, 100)]) + .with_delegations(vec![(3, 1, 100), (4, 1, 100), (5, 2, 100), (6, 2, 100)]) .build() .execute_with(|| { roll_to(11); - assert_ok!(Stake::leave_candidates(Origin::signed(2), 2)); - let info = Stake::collator_state2(&2).unwrap(); - assert_eq!(info.state, CollatorStatus::Leaving(5)); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(2), + 2 + )); + let info = ParachainStaking::candidate_info(&2).unwrap(); + assert_eq!(info.status, CollatorStatus::Leaving(5)); roll_to(21); + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(2), + 2, + 2 + )); // we must exclude leaving collators from rewards while // holding them retroactively accountable for previous faults // (within the last T::SlashingWindow blocks) @@ -2984,14 +3949,14 @@ fn collator_exit_executes_after_delay() { Event::CollatorChosen(3, 1, 700), Event::CollatorChosen(3, 2, 400), Event::NewRound(10, 3, 2, 1100), - Event::CollatorScheduledExit(3, 2, 5), + Event::CandidateScheduledExit(3, 2, 5), Event::CollatorChosen(4, 1, 700), Event::NewRound(15, 4, 1, 700), - Event::CollatorLeft(2, 400, 700), Event::CollatorChosen(5, 1, 700), Event::NewRound(20, 5, 1, 700), + Event::CandidateLeft(2, 400, 700), ]; - assert_eq!(events(), expected); + assert_eq_events!(expected); }); } @@ -3022,18 +3987,28 @@ fn collator_selection_chooses_top_candidates() { Event::CollatorChosen(2, 5, 60), Event::NewRound(5, 2, 5, 400), ]; - assert_eq!(events(), expected); - assert_ok!(Stake::leave_candidates(Origin::signed(6), 6)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::CollatorScheduledExit(2, 6, 4)) - ); + assert_eq_events!(expected.clone()); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(6), + 6 + )); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateScheduledExit( + 2, 6, 4 + ))); roll_to(21); - assert_ok!(Stake::join_candidates(Origin::signed(6), 69u128, 100u32)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::JoinedCollatorCandidates(6, 69u128, 469u128)) - ); + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(6), + 6, + 0 + )); + assert_ok!(ParachainStaking::join_candidates( + Origin::signed(6), + 69u128, + 100u32 + )); + assert_last_event!(MetaEvent::ParachainStaking( + Event::JoinedCollatorCandidates(6, 69u128, 469u128,) + )); roll_to(27); // should choose top TotalSelectedCandidates (5), in order let expected = vec![ @@ -3043,14 +4018,13 @@ fn collator_selection_chooses_top_candidates() { Event::CollatorChosen(2, 4, 70), Event::CollatorChosen(2, 5, 60), Event::NewRound(5, 2, 5, 400), - Event::CollatorScheduledExit(2, 6, 4), + Event::CandidateScheduledExit(2, 6, 4), Event::CollatorChosen(3, 1, 100), Event::CollatorChosen(3, 2, 90), Event::CollatorChosen(3, 3, 80), Event::CollatorChosen(3, 4, 70), Event::CollatorChosen(3, 5, 60), Event::NewRound(10, 3, 5, 400), - Event::CollatorLeft(6, 50, 400), Event::CollatorChosen(4, 1, 100), Event::CollatorChosen(4, 2, 90), Event::CollatorChosen(4, 3, 80), @@ -3063,6 +4037,7 @@ fn collator_selection_chooses_top_candidates() { Event::CollatorChosen(5, 4, 70), Event::CollatorChosen(5, 5, 60), Event::NewRound(20, 5, 5, 400), + Event::CandidateLeft(6, 50, 400), Event::JoinedCollatorCandidates(6, 69, 469), Event::CollatorChosen(6, 1, 100), Event::CollatorChosen(6, 2, 90), @@ -3071,80 +4046,7 @@ fn collator_selection_chooses_top_candidates() { Event::CollatorChosen(6, 6, 69), Event::NewRound(25, 6, 5, 409), ]; - assert_eq!(events(), expected); - }); -} - -#[test] -fn exit_queue_executes_in_order() { - ExtBuilder::default() - .with_balances(vec![ - (1, 1000), - (2, 1000), - (3, 1000), - (4, 1000), - (5, 1000), - (6, 1000), - (7, 33), - (8, 33), - (9, 33), - ]) - .with_candidates(vec![(1, 100), (2, 90), (3, 80), (4, 70), (5, 60), (6, 50)]) - .build() - .execute_with(|| { - roll_to(8); - // should choose top TotalSelectedCandidates (5), in order - let mut expected = vec![ - Event::CollatorChosen(2, 1, 100), - Event::CollatorChosen(2, 2, 90), - Event::CollatorChosen(2, 3, 80), - Event::CollatorChosen(2, 4, 70), - Event::CollatorChosen(2, 5, 60), - Event::NewRound(5, 2, 5, 400), - ]; - assert_eq!(events(), expected); - assert_ok!(Stake::leave_candidates(Origin::signed(6), 6)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::CollatorScheduledExit(2, 6, 4)) - ); - roll_to(11); - assert_ok!(Stake::leave_candidates(Origin::signed(5), 5)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::CollatorScheduledExit(3, 5, 5)) - ); - roll_to(16); - assert_ok!(Stake::leave_candidates(Origin::signed(4), 4)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::CollatorScheduledExit(4, 4, 6)) - ); - roll_to(21); - let mut new_events = vec![ - Event::CollatorScheduledExit(2, 6, 4), - Event::CollatorChosen(3, 1, 100), - Event::CollatorChosen(3, 2, 90), - Event::CollatorChosen(3, 3, 80), - Event::CollatorChosen(3, 4, 70), - Event::CollatorChosen(3, 5, 60), - Event::NewRound(10, 3, 5, 400), - Event::CollatorScheduledExit(3, 5, 5), - Event::CollatorLeft(6, 50, 400), - Event::CollatorChosen(4, 1, 100), - Event::CollatorChosen(4, 2, 90), - Event::CollatorChosen(4, 3, 80), - Event::CollatorChosen(4, 4, 70), - Event::NewRound(15, 4, 4, 340), - Event::CollatorScheduledExit(4, 4, 6), - Event::CollatorLeft(5, 60, 340), - Event::CollatorChosen(5, 1, 100), - Event::CollatorChosen(5, 2, 90), - Event::CollatorChosen(5, 3, 80), - Event::NewRound(20, 5, 3, 270), - ]; - expected.append(&mut new_events); - assert_eq!(events(), expected); + assert_eq_events!(expected); }); } @@ -3175,7 +4077,7 @@ fn payout_distribution_to_solo_collators() { Event::CollatorChosen(2, 5, 60), Event::NewRound(5, 2, 5, 400), ]; - assert_eq!(events(), expected); + assert_eq_events!(expected.clone()); // ~ set block author as 1 for all blocks this round set_author(2, 1, 100); roll_to(16); @@ -3187,16 +4089,16 @@ fn payout_distribution_to_solo_collators() { Event::CollatorChosen(3, 4, 70), Event::CollatorChosen(3, 5, 60), Event::NewRound(10, 3, 5, 400), - Event::Rewarded(1, 305), Event::CollatorChosen(4, 1, 100), Event::CollatorChosen(4, 2, 90), Event::CollatorChosen(4, 3, 80), Event::CollatorChosen(4, 4, 70), Event::CollatorChosen(4, 5, 60), Event::NewRound(15, 4, 5, 400), + Event::Rewarded(1, 305), ]; expected.append(&mut new); - assert_eq!(events(), expected); + assert_eq_events!(expected.clone()); // ~ set block author as 1 for 3 blocks this round set_author(4, 1, 60); // ~ set block author as 2 for 2 blocks this round @@ -3210,24 +4112,24 @@ fn payout_distribution_to_solo_collators() { Event::CollatorChosen(5, 4, 70), Event::CollatorChosen(5, 5, 60), Event::NewRound(20, 5, 5, 400), - Event::Rewarded(1, 192), - Event::Rewarded(2, 128), Event::CollatorChosen(6, 1, 100), Event::CollatorChosen(6, 2, 90), Event::CollatorChosen(6, 3, 80), Event::CollatorChosen(6, 4, 70), Event::CollatorChosen(6, 5, 60), Event::NewRound(25, 6, 5, 400), + Event::Rewarded(1, 192), + Event::Rewarded(2, 128), ]; expected.append(&mut new1); - assert_eq!(events(), expected); + assert_eq_events!(expected.clone()); // ~ each collator produces 1 block this round set_author(6, 1, 20); set_author(6, 2, 20); set_author(6, 3, 20); set_author(6, 4, 20); set_author(6, 5, 20); - roll_to(36); + roll_to(39); // pay 20% issuance for all collators let mut new2 = vec![ Event::CollatorChosen(7, 1, 100), @@ -3236,34 +4138,34 @@ fn payout_distribution_to_solo_collators() { Event::CollatorChosen(7, 4, 70), Event::CollatorChosen(7, 5, 60), Event::NewRound(30, 7, 5, 400), - Event::Rewarded(5, 67), - Event::Rewarded(3, 67), - Event::Rewarded(4, 67), - Event::Rewarded(1, 67), - Event::Rewarded(2, 67), Event::CollatorChosen(8, 1, 100), Event::CollatorChosen(8, 2, 90), Event::CollatorChosen(8, 3, 80), Event::CollatorChosen(8, 4, 70), Event::CollatorChosen(8, 5, 60), Event::NewRound(35, 8, 5, 400), + Event::Rewarded(5, 67), + Event::Rewarded(3, 67), + Event::Rewarded(4, 67), + Event::Rewarded(1, 67), + Event::Rewarded(2, 67), ]; expected.append(&mut new2); - assert_eq!(events(), expected); + assert_eq_events!(expected); // check that distributing rewards clears awarded pts - assert!(Stake::awarded_pts(1, 1).is_zero()); - assert!(Stake::awarded_pts(4, 1).is_zero()); - assert!(Stake::awarded_pts(4, 2).is_zero()); - assert!(Stake::awarded_pts(6, 1).is_zero()); - assert!(Stake::awarded_pts(6, 2).is_zero()); - assert!(Stake::awarded_pts(6, 3).is_zero()); - assert!(Stake::awarded_pts(6, 4).is_zero()); - assert!(Stake::awarded_pts(6, 5).is_zero()); + assert!(ParachainStaking::awarded_pts(1, 1).is_zero()); + assert!(ParachainStaking::awarded_pts(4, 1).is_zero()); + assert!(ParachainStaking::awarded_pts(4, 2).is_zero()); + assert!(ParachainStaking::awarded_pts(6, 1).is_zero()); + assert!(ParachainStaking::awarded_pts(6, 2).is_zero()); + assert!(ParachainStaking::awarded_pts(6, 3).is_zero()); + assert!(ParachainStaking::awarded_pts(6, 4).is_zero()); + assert!(ParachainStaking::awarded_pts(6, 5).is_zero()); }); } #[test] -fn multiple_nominations() { +fn multiple_delegations() { ExtBuilder::default() .with_balances(vec![ (1, 100), @@ -3278,7 +4180,7 @@ fn multiple_nominations() { (10, 100), ]) .with_candidates(vec![(1, 20), (2, 20), (3, 20), (4, 20), (5, 10)]) - .with_nominations(vec![ + .with_delegations(vec![ (6, 1, 10), (7, 1, 10), (8, 2, 10), @@ -3297,15 +4199,15 @@ fn multiple_nominations() { Event::CollatorChosen(2, 5, 10), Event::NewRound(5, 2, 5, 140), ]; - assert_eq!(events(), expected); - assert_ok!(Stake::nominate(Origin::signed(6), 2, 10, 10, 10)); - assert_ok!(Stake::nominate(Origin::signed(6), 3, 10, 10, 10)); - assert_ok!(Stake::nominate(Origin::signed(6), 4, 10, 10, 10)); + assert_eq_events!(expected.clone()); + assert_ok!(ParachainStaking::delegate(Origin::signed(6), 2, 10, 10, 10)); + assert_ok!(ParachainStaking::delegate(Origin::signed(6), 3, 10, 10, 10)); + assert_ok!(ParachainStaking::delegate(Origin::signed(6), 4, 10, 10, 10)); roll_to(16); let mut new = vec![ - Event::Nomination(6, 10, 2, NominatorAdded::AddedToTop { new_total: 50 }), - Event::Nomination(6, 10, 3, NominatorAdded::AddedToTop { new_total: 30 }), - Event::Nomination(6, 10, 4, NominatorAdded::AddedToTop { new_total: 30 }), + Event::Delegation(6, 10, 2, DelegatorAdded::AddedToTop { new_total: 50 }), + Event::Delegation(6, 10, 3, DelegatorAdded::AddedToTop { new_total: 30 }), + Event::Delegation(6, 10, 4, DelegatorAdded::AddedToTop { new_total: 30 }), Event::CollatorChosen(3, 1, 50), Event::CollatorChosen(3, 2, 50), Event::CollatorChosen(3, 3, 30), @@ -3320,10 +4222,16 @@ fn multiple_nominations() { Event::NewRound(15, 4, 5, 170), ]; expected.append(&mut new); - assert_eq!(events(), expected); + assert_eq_events!(expected.clone()); roll_to(21); - assert_ok!(Stake::nominate(Origin::signed(7), 2, 80, 10, 10)); - assert_ok!(Stake::nominate(Origin::signed(10), 2, 10, 10, 10),); + assert_ok!(ParachainStaking::delegate(Origin::signed(7), 2, 80, 10, 10)); + assert_ok!(ParachainStaking::delegate( + Origin::signed(10), + 2, + 10, + 10, + 10 + ),); roll_to(26); let mut new2 = vec![ Event::CollatorChosen(5, 1, 50), @@ -3332,8 +4240,8 @@ fn multiple_nominations() { Event::CollatorChosen(5, 4, 30), Event::CollatorChosen(5, 5, 10), Event::NewRound(20, 5, 5, 170), - Event::Nomination(7, 80, 2, NominatorAdded::AddedToTop { new_total: 130 }), - Event::Nomination(10, 10, 2, NominatorAdded::AddedToBottom), + Event::Delegation(7, 80, 2, DelegatorAdded::AddedToTop { new_total: 130 }), + Event::Delegation(10, 10, 2, DelegatorAdded::AddedToBottom), Event::CollatorChosen(6, 1, 50), Event::CollatorChosen(6, 2, 130), Event::CollatorChosen(6, 3, 30), @@ -3342,15 +4250,17 @@ fn multiple_nominations() { Event::NewRound(25, 6, 5, 250), ]; expected.append(&mut new2); - assert_eq!(events(), expected); - assert_ok!(Stake::leave_candidates(Origin::signed(2), 5)); - assert_eq!( - last_event(), - MetaEvent::Stake(Event::CollatorScheduledExit(6, 2, 8)) - ); + assert_eq_events!(expected.clone()); + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(2), + 5 + )); + assert_last_event!(MetaEvent::ParachainStaking(Event::CandidateScheduledExit( + 6, 2, 8 + ))); roll_to(31); let mut new3 = vec![ - Event::CollatorScheduledExit(6, 2, 8), + Event::CandidateScheduledExit(6, 2, 8), Event::CollatorChosen(7, 1, 50), Event::CollatorChosen(7, 3, 30), Event::CollatorChosen(7, 4, 30), @@ -3358,16 +4268,24 @@ fn multiple_nominations() { Event::NewRound(30, 7, 4, 120), ]; expected.append(&mut new3); - assert_eq!(events(), expected); - // verify that nominations are removed after collator leaves, not before - assert_eq!(Stake::nominator_state2(7).unwrap().total, 90); + assert_eq_events!(expected); + // verify that delegations are removed after collator leaves, not before + assert_eq!(ParachainStaking::delegator_state(7).unwrap().total, 90); assert_eq!( - Stake::nominator_state2(7).unwrap().nominations.0.len(), + ParachainStaking::delegator_state(7) + .unwrap() + .delegations + .0 + .len(), 2usize ); - assert_eq!(Stake::nominator_state2(6).unwrap().total, 40); + assert_eq!(ParachainStaking::delegator_state(6).unwrap().total, 40); assert_eq!( - Stake::nominator_state2(6).unwrap().nominations.0.len(), + ParachainStaking::delegator_state(6) + .unwrap() + .delegations + .0 + .len(), 4usize ); assert_eq!(Balances::reserved_balance(&6), 40); @@ -3375,14 +4293,27 @@ fn multiple_nominations() { assert_eq!(Balances::free_balance(&6), 60); assert_eq!(Balances::free_balance(&7), 10); roll_to(40); - assert_eq!(Stake::nominator_state2(7).unwrap().total, 10); - assert_eq!(Stake::nominator_state2(6).unwrap().total, 30); + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(2), + 2, + 5 + )); + assert_eq!(ParachainStaking::delegator_state(7).unwrap().total, 10); + assert_eq!(ParachainStaking::delegator_state(6).unwrap().total, 30); assert_eq!( - Stake::nominator_state2(7).unwrap().nominations.0.len(), + ParachainStaking::delegator_state(7) + .unwrap() + .delegations + .0 + .len(), 1usize ); assert_eq!( - Stake::nominator_state2(6).unwrap().nominations.0.len(), + ParachainStaking::delegator_state(6) + .unwrap() + .delegations + .0 + .len(), 3usize ); assert_eq!(Balances::reserved_balance(&6), 30); @@ -3393,7 +4324,60 @@ fn multiple_nominations() { } #[test] -fn payouts_follow_nomination_changes() { +// The test verifies that the pending revoke request is removed by 2's exit so there is no dangling +// revoke request after 2 exits +fn execute_leave_candidate_removes_delegations() { + ExtBuilder::default() + .with_balances(vec![(1, 100), (2, 100), (3, 100), (4, 100)]) + .with_candidates(vec![(1, 20), (2, 20)]) + .with_delegations(vec![(3, 1, 10), (3, 2, 10), (4, 1, 10), (4, 2, 10)]) + .build() + .execute_with(|| { + // Verifies the revocation count is originally at 0 + assert_eq!( + ParachainStaking::delegator_state(3) + .unwrap() + .requests + .revocations_count, + 0 + ); + + assert_ok!(ParachainStaking::schedule_leave_candidates( + Origin::signed(2), + 2 + )); + assert_ok!(ParachainStaking::schedule_revoke_delegation( + Origin::signed(3), + 2 + )); + // Verifies the revocation count has been updated to 1 + assert_eq!( + ParachainStaking::delegator_state(3) + .unwrap() + .requests + .revocations_count, + 1 + ); + + roll_to(16); + assert_ok!(ParachainStaking::execute_leave_candidates( + Origin::signed(2), + 2, + 2 + )); + // Verifies the revocation count has been reduced to 0 + assert_eq!( + ParachainStaking::delegator_state(3) + .unwrap() + .requests + .revocations_count, + 0 + ); + }); +} + +#[test] +fn payouts_follow_delegation_changes() { ExtBuilder::default() .with_balances(vec![ (1, 100), @@ -3408,7 +4392,7 @@ fn payouts_follow_nomination_changes() { (10, 100), ]) .with_candidates(vec![(1, 20), (2, 20), (3, 20), (4, 20), (5, 10)]) - .with_nominations(vec![ + .with_delegations(vec![ (6, 1, 10), (7, 1, 10), (8, 2, 10), @@ -3427,11 +4411,11 @@ fn payouts_follow_nomination_changes() { Event::CollatorChosen(2, 5, 10), Event::NewRound(5, 2, 5, 140), ]; - assert_eq!(events(), expected); + assert_eq_events!(expected.clone()); // ~ set block author as 1 for all blocks this round set_author(2, 1, 100); roll_to(16); - // distribute total issuance to collator 1 and its nominators 6, 7, 19 + // distribute total issuance to collator 1 and its delegators 6, 7, 19 let mut new = vec![ Event::CollatorChosen(3, 1, 50), Event::CollatorChosen(3, 2, 40), @@ -3439,224 +4423,205 @@ fn payouts_follow_nomination_changes() { Event::CollatorChosen(3, 4, 20), Event::CollatorChosen(3, 5, 10), Event::NewRound(10, 3, 5, 140), - Event::Rewarded(1, 26), - Event::Rewarded(6, 8), - Event::Rewarded(7, 8), - Event::Rewarded(10, 8), Event::CollatorChosen(4, 1, 50), Event::CollatorChosen(4, 2, 40), Event::CollatorChosen(4, 3, 20), Event::CollatorChosen(4, 4, 20), Event::CollatorChosen(4, 5, 10), Event::NewRound(15, 4, 5, 140), + Event::Rewarded(1, 26), + Event::Rewarded(6, 8), + Event::Rewarded(7, 8), + Event::Rewarded(10, 8), ]; expected.append(&mut new); - assert_eq!(events(), expected); + assert_eq_events!(expected.clone()); // ~ set block author as 1 for all blocks this round set_author(3, 1, 100); set_author(4, 1, 100); set_author(5, 1, 100); - // 1. ensure nominators are paid for 2 rounds after they leave + set_author(6, 1, 100); + // 1. ensure delegators are paid for 2 rounds after they leave assert_noop!( - Stake::leave_nominators(Origin::signed(66), 10), - Error::::NominatorDNE + ParachainStaking::schedule_leave_delegators(Origin::signed(66)), + Error::::DelegatorDNE ); - assert_ok!(Stake::leave_nominators(Origin::signed(6), 10)); - // fast forward to block in which nominator 6 exit executes + assert_ok!(ParachainStaking::schedule_leave_delegators(Origin::signed( + 6 + ))); + // fast forward to block in which delegator 6 exit executes roll_to(25); + assert_ok!(ParachainStaking::execute_leave_delegators( + Origin::signed(6), + 6, + 10 + )); // keep paying 6 (note: inflation is in terms of total issuance so that's why 1 is 21) let mut new2 = vec![ - Event::NominatorExitScheduled(4, 6, 6), - Event::Rewarded(1, 27), - Event::Rewarded(6, 8), - Event::Rewarded(7, 8), - Event::Rewarded(10, 8), + Event::DelegatorExitScheduled(4, 6, 6), Event::CollatorChosen(5, 1, 50), Event::CollatorChosen(5, 2, 40), Event::CollatorChosen(5, 3, 20), Event::CollatorChosen(5, 4, 20), Event::CollatorChosen(5, 5, 10), Event::NewRound(20, 5, 5, 140), - Event::Rewarded(1, 29), - Event::Rewarded(6, 9), - Event::Rewarded(7, 9), - Event::Rewarded(10, 9), - Event::NominatorLeftCollator(6, 1, 10, 40), - Event::NominatorLeft(6, 10), - Event::CollatorChosen(6, 1, 40), + Event::Rewarded(1, 27), + Event::Rewarded(6, 8), + Event::Rewarded(7, 8), + Event::Rewarded(10, 8), + Event::CollatorChosen(6, 1, 50), Event::CollatorChosen(6, 2, 40), Event::CollatorChosen(6, 3, 20), Event::CollatorChosen(6, 4, 20), Event::CollatorChosen(6, 5, 10), - Event::NewRound(25, 6, 5, 130), + Event::NewRound(25, 6, 5, 140), + Event::Rewarded(1, 29), + Event::Rewarded(6, 9), + Event::Rewarded(7, 9), + Event::Rewarded(10, 9), + Event::DelegatorLeftCandidate(6, 1, 10, 40), + Event::DelegatorLeft(6, 10), ]; expected.append(&mut new2); - assert_eq!(events(), expected); + assert_eq_events!(expected.clone()); // 6 won't be paid for this round because they left already - set_author(6, 1, 100); - roll_to(30); + set_author(7, 1, 100); + roll_to(35); // keep paying 6 let mut new3 = vec![ - Event::Rewarded(1, 30), - Event::Rewarded(6, 9), - Event::Rewarded(7, 9), - Event::Rewarded(10, 9), Event::CollatorChosen(7, 1, 40), Event::CollatorChosen(7, 2, 40), Event::CollatorChosen(7, 3, 20), Event::CollatorChosen(7, 4, 20), Event::CollatorChosen(7, 5, 10), Event::NewRound(30, 7, 5, 130), - ]; - expected.append(&mut new3); - assert_eq!(events(), expected); - set_author(7, 1, 100); - roll_to(35); - // no more paying 6 - let mut new4 = vec![ - Event::Rewarded(1, 36), - Event::Rewarded(7, 12), - Event::Rewarded(10, 12), + Event::Rewarded(1, 30), + Event::Rewarded(6, 9), + Event::Rewarded(7, 9), + Event::Rewarded(10, 9), Event::CollatorChosen(8, 1, 40), Event::CollatorChosen(8, 2, 40), Event::CollatorChosen(8, 3, 20), Event::CollatorChosen(8, 4, 20), Event::CollatorChosen(8, 5, 10), Event::NewRound(35, 8, 5, 130), + Event::Rewarded(1, 32), + Event::Rewarded(6, 10), + Event::Rewarded(7, 10), + Event::Rewarded(10, 10), ]; - expected.append(&mut new4); - assert_eq!(events(), expected); + expected.append(&mut new3); + assert_eq_events!(expected.clone()); set_author(8, 1, 100); - assert_ok!(Stake::nominate(Origin::signed(8), 1, 10, 10, 10)); roll_to(40); - // new nomination is not rewarded yet - let mut new5 = vec![ - Event::Nomination(8, 10, 1, NominatorAdded::AddedToTop { new_total: 50 }), - Event::Rewarded(1, 38), - Event::Rewarded(7, 13), - Event::Rewarded(10, 13), - Event::CollatorChosen(9, 1, 50), + // no more paying 6 + let mut new4 = vec![ + Event::CollatorChosen(9, 1, 40), Event::CollatorChosen(9, 2, 40), Event::CollatorChosen(9, 3, 20), Event::CollatorChosen(9, 4, 20), Event::CollatorChosen(9, 5, 10), - Event::NewRound(40, 9, 5, 140), + Event::NewRound(40, 9, 5, 130), + Event::Rewarded(1, 38), + Event::Rewarded(7, 13), + Event::Rewarded(10, 13), ]; - expected.append(&mut new5); - assert_eq!(events(), expected); + expected.append(&mut new4); + assert_eq_events!(expected.clone()); set_author(9, 1, 100); + assert_ok!(ParachainStaking::delegate(Origin::signed(8), 1, 10, 10, 10)); roll_to(45); - // new nomination is still not rewarded yet - let mut new6 = vec![ - Event::Rewarded(1, 40), - Event::Rewarded(7, 13), - Event::Rewarded(10, 13), + // new delegation is not rewarded yet + let mut new5 = vec![ + Event::Delegation(8, 10, 1, DelegatorAdded::AddedToTop { new_total: 50 }), Event::CollatorChosen(10, 1, 50), Event::CollatorChosen(10, 2, 40), Event::CollatorChosen(10, 3, 20), Event::CollatorChosen(10, 4, 20), Event::CollatorChosen(10, 5, 10), Event::NewRound(45, 10, 5, 140), + Event::Rewarded(1, 40), + Event::Rewarded(7, 13), + Event::Rewarded(10, 13), ]; - expected.append(&mut new6); - assert_eq!(events(), expected); + expected.append(&mut new5); + assert_eq_events!(expected.clone()); + set_author(10, 1, 100); roll_to(50); - // new nomination is rewarded for first time, 2 rounds after joining (`RewardPaymentDelay` = 2) - let mut new7 = vec![ - Event::Rewarded(1, 36), - Event::Rewarded(7, 11), - Event::Rewarded(8, 11), - Event::Rewarded(10, 11), + // new delegation not rewarded yet + let mut new6 = vec![ Event::CollatorChosen(11, 1, 50), Event::CollatorChosen(11, 2, 40), Event::CollatorChosen(11, 3, 20), Event::CollatorChosen(11, 4, 20), Event::CollatorChosen(11, 5, 10), Event::NewRound(50, 11, 5, 140), + Event::Rewarded(1, 42), + Event::Rewarded(7, 14), + Event::Rewarded(10, 14), ]; - expected.append(&mut new7); - assert_eq!(events(), expected); + expected.append(&mut new6); + assert_eq_events!(expected.clone()); + roll_to(55); + // new delegation is rewarded for first time + // 2 rounds after joining (`RewardPaymentDelay` = 2) + let mut new7 = vec![ + Event::CollatorChosen(12, 1, 50), + Event::CollatorChosen(12, 2, 40), + Event::CollatorChosen(12, 3, 20), + Event::CollatorChosen(12, 4, 20), + Event::CollatorChosen(12, 5, 10), + Event::NewRound(55, 12, 5, 140), + Event::Rewarded(1, 39), + Event::Rewarded(7, 12), + Event::Rewarded(10, 12), + Event::Rewarded(8, 12), + ]; + expected.append(&mut new7); + assert_eq_events!(expected); }); } #[test] -fn nominations_merged_before_reward_payout() { +fn bottom_delegations_are_empty_when_top_delegations_not_full() { ExtBuilder::default() - .with_balances(vec![(1, 20), (2, 20), (3, 20), (4, 20), (5, 120)]) - .with_candidates(vec![(1, 20), (2, 20), (3, 20), (4, 20)]) - .with_nominations(vec![(5, 1, 30), (5, 2, 30), (5, 3, 30), (5, 4, 30)]) + .with_balances(vec![(1, 20), (2, 10), (3, 10), (4, 10), (5, 10)]) + .with_candidates(vec![(1, 20)]) .build() .execute_with(|| { - roll_to(8); - set_author(1, 1, 1); - set_author(1, 2, 1); - set_author(1, 3, 1); - set_author(1, 4, 1); - roll_to(16); - let expected_events = vec![ - Event::CollatorChosen(2, 1, 50), - Event::CollatorChosen(2, 2, 50), - Event::CollatorChosen(2, 3, 50), - Event::CollatorChosen(2, 4, 50), - Event::NewRound(5, 2, 4, 200), - Event::Rewarded(3, 1), - Event::Rewarded(4, 1), - Event::Rewarded(1, 1), - Event::Rewarded(2, 1), - // ALL REWARDS FOR 5 are merged into one payment + event - Event::Rewarded(5, 4), - Event::CollatorChosen(3, 1, 50), - Event::CollatorChosen(3, 2, 50), - Event::CollatorChosen(3, 3, 50), - Event::CollatorChosen(3, 4, 50), - Event::NewRound(10, 3, 4, 200), - Event::CollatorChosen(4, 1, 50), - Event::CollatorChosen(4, 2, 50), - Event::CollatorChosen(4, 3, 50), - Event::CollatorChosen(4, 4, 50), - Event::NewRound(15, 4, 4, 200), - ]; - assert_eq!(events(), expected_events); + // no top delegators => no bottom delegators + let top_delegations = ParachainStaking::top_delegations(1).unwrap(); + let bottom_delegations = ParachainStaking::bottom_delegations(1).unwrap(); + assert!(top_delegations.delegations.is_empty()); + assert!(bottom_delegations.delegations.is_empty()); + // 1 delegator => 1 top delegator, 0 bottom delegators + assert_ok!(ParachainStaking::delegate(Origin::signed(2), 1, 10, 10, 10)); + let top_delegations = ParachainStaking::top_delegations(1).unwrap(); + let bottom_delegations = ParachainStaking::bottom_delegations(1).unwrap(); + assert_eq!(top_delegations.delegations.len(), 1usize); + assert!(bottom_delegations.delegations.is_empty()); + // 2 delegators => 2 top delegators, 0 bottom delegators + assert_ok!(ParachainStaking::delegate(Origin::signed(3), 1, 10, 10, 10)); + let top_delegations = ParachainStaking::top_delegations(1).unwrap(); + let bottom_delegations = ParachainStaking::bottom_delegations(1).unwrap(); + assert_eq!(top_delegations.delegations.len(), 2usize); + assert!(bottom_delegations.delegations.is_empty()); + // 3 delegators => 3 top delegators, 0 bottom delegators + assert_ok!(ParachainStaking::delegate(Origin::signed(4), 1, 10, 10, 10)); + let top_delegations = ParachainStaking::top_delegations(1).unwrap(); + let bottom_delegations = ParachainStaking::bottom_delegations(1).unwrap(); + assert_eq!(top_delegations.delegations.len(), 3usize); + assert!(bottom_delegations.delegations.is_empty()); + // 4 delegators => 4 top delegators, 0 bottom delegators + assert_ok!(ParachainStaking::delegate(Origin::signed(5), 1, 10, 10, 10)); + let top_delegations = ParachainStaking::top_delegations(1).unwrap(); + let bottom_delegations = ParachainStaking::bottom_delegations(1).unwrap(); + assert_eq!(top_delegations.delegations.len(), 4usize); + assert!(bottom_delegations.delegations.is_empty()); }); } #[test] -// MaxNominatorsPerCollator = 4 -fn bottom_nominations_are_empty_when_top_nominations_not_full() { - ExtBuilder::default() - .with_balances(vec![(1, 20), (2, 10), (3, 10), (4, 10), (5, 10)]) - .with_candidates(vec![(1, 20)]) - .build() - .execute_with(|| { - // no top nominators => no bottom nominators - let collator_state = Stake::collator_state2(1).unwrap(); - assert!(collator_state.top_nominators.is_empty()); - assert!(collator_state.bottom_nominators.is_empty()); - // 1 nominator => 1 top nominator, 0 bottom nominators - assert_ok!(Stake::nominate(Origin::signed(2), 1, 10, 10, 10)); - let collator_state = Stake::collator_state2(1).unwrap(); - assert_eq!(collator_state.top_nominators.len(), 1usize); - assert!(collator_state.bottom_nominators.is_empty()); - // 2 nominators => 2 top nominators, 0 bottom nominators - assert_ok!(Stake::nominate(Origin::signed(3), 1, 10, 10, 10)); - let collator_state = Stake::collator_state2(1).unwrap(); - assert_eq!(collator_state.top_nominators.len(), 2usize); - assert!(collator_state.bottom_nominators.is_empty()); - // 3 nominators => 3 top nominators, 0 bottom nominators - assert_ok!(Stake::nominate(Origin::signed(4), 1, 10, 10, 10)); - let collator_state = Stake::collator_state2(1).unwrap(); - assert_eq!(collator_state.top_nominators.len(), 3usize); - assert!(collator_state.bottom_nominators.is_empty()); - // 4 nominators => 4 top nominators, 0 bottom nominators - assert_ok!(Stake::nominate(Origin::signed(5), 1, 10, 10, 10)); - let collator_state = Stake::collator_state2(1).unwrap(); - assert_eq!(collator_state.top_nominators.len(), 4usize); - assert!(collator_state.bottom_nominators.is_empty()); - }); -} - -#[test] -// MaxNominatorsPerCollator = 4 fn candidate_pool_updates_when_total_counted_changes() { ExtBuilder::default() .with_balances(vec![ @@ -3671,7 +4636,7 @@ fn candidate_pool_updates_when_total_counted_changes() { (10, 18), ]) .with_candidates(vec![(1, 20)]) - .with_nominations(vec![ + .with_delegations(vec![ (3, 1, 11), (4, 1, 12), (5, 1, 13), @@ -3684,32 +4649,66 @@ fn candidate_pool_updates_when_total_counted_changes() { .build() .execute_with(|| { fn is_candidate_pool_bond(account: u64, bond: u128) { - let pool = Stake::candidate_pool(); + let pool = ParachainStaking::candidate_pool(); for candidate in pool.0 { if candidate.owner == account { - assert_eq!(candidate.amount, bond); + assert_eq!( + candidate.amount, bond, + "Candidate Bond {:?} is Not Equal to Expected: {:?}", + candidate.amount, bond + ); } } } // 15 + 16 + 17 + 18 + 20 = 86 (top 4 + self bond) is_candidate_pool_bond(1, 86); - assert_ok!(Stake::nominator_bond_more(Origin::signed(3), 1, 8)); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(3), + 1, + 8 + )); + // 3: 11 -> 19 => 3 is in top, bumps out 7 // 16 + 17 + 18 + 19 + 20 = 90 (top 4 + self bond) is_candidate_pool_bond(1, 90); - assert_ok!(Stake::nominator_bond_more(Origin::signed(4), 1, 8)); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(4), + 1, + 8 + )); + // 4: 12 -> 20 => 4 is in top, bumps out 8 // 17 + 18 + 19 + 20 + 20 = 94 (top 4 + self bond) is_candidate_pool_bond(1, 94); - assert_ok!(Stake::nominator_bond_less(Origin::signed(10), 1, 3)); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(10), + 1, + 3 + )); + roll_to(30); + // 10: 18 -> 15 => 10 bumped to bottom, 8 bumped to top (- 18 + 16 = -2 for count) + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(10), + 10, + 1 + )); // 16 + 17 + 19 + 20 + 20 = 92 (top 4 + self bond) is_candidate_pool_bond(1, 92); - assert_ok!(Stake::nominator_bond_less(Origin::signed(9), 1, 4)); + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(9), + 1, + 4 + )); + roll_to(40); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(9), + 9, + 1 + )); // 15 + 16 + 19 + 20 + 20 = 90 (top 4 + self bond) is_candidate_pool_bond(1, 90); }); } #[test] -// MaxNominatorsPerCollator = 4 fn only_top_collators_are_counted() { ExtBuilder::default() .with_balances(vec![ @@ -3724,7 +4723,7 @@ fn only_top_collators_are_counted() { (10, 18), ]) .with_candidates(vec![(1, 20)]) - .with_nominations(vec![ + .with_delegations(vec![ (3, 1, 11), (4, 1, 12), (5, 1, 13), @@ -3736,72 +4735,58 @@ fn only_top_collators_are_counted() { ]) .build() .execute_with(|| { - // sanity check that 3-10 are nominators immediately + // sanity check that 3-10 are delegators immediately for i in 3..11 { - assert!(Stake::is_nominator(&i)); + assert!(ParachainStaking::is_delegator(&i)); } - let mut expected_events = Vec::new(); - let collator_state = Stake::collator_state2(1).unwrap(); + let collator_state = ParachainStaking::candidate_info(1).unwrap(); // 15 + 16 + 17 + 18 + 20 = 86 (top 4 + self bond) assert_eq!(collator_state.total_counted, 86); - // 11 + 12 + 13 + 14 = 50 - assert_eq!( - collator_state.total_counted + 50, - collator_state.total_backing - ); // bump bottom to the top - assert_ok!(Stake::nominator_bond_more(Origin::signed(3), 1, 8)); - expected_events.push(Event::NominationIncreased(3, 1, 8, true)); - assert_eq!(events(), expected_events); - let collator_state = Stake::collator_state2(1).unwrap(); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(3), + 1, + 8 + )); + assert_event_emitted!(Event::DelegationIncreased(3, 1, 8, true)); + let collator_state = ParachainStaking::candidate_info(1).unwrap(); // 16 + 17 + 18 + 19 + 20 = 90 (top 4 + self bond) assert_eq!(collator_state.total_counted, 90); - // 12 + 13 + 14 + 15 = 54 - assert_eq!( - collator_state.total_counted + 54, - collator_state.total_backing - ); // bump bottom to the top - assert_ok!(Stake::nominator_bond_more(Origin::signed(4), 1, 8)); - expected_events.push(Event::NominationIncreased(4, 1, 8, true)); - assert_eq!(events(), expected_events); - let collator_state = Stake::collator_state2(1).unwrap(); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(4), + 1, + 8 + )); + assert_event_emitted!(Event::DelegationIncreased(4, 1, 8, true)); + let collator_state = ParachainStaking::candidate_info(1).unwrap(); // 17 + 18 + 19 + 20 + 20 = 94 (top 4 + self bond) assert_eq!(collator_state.total_counted, 94); - // 13 + 14 + 15 + 16 = 58 - assert_eq!( - collator_state.total_counted + 58, - collator_state.total_backing - ); // bump bottom to the top - assert_ok!(Stake::nominator_bond_more(Origin::signed(5), 1, 8)); - expected_events.push(Event::NominationIncreased(5, 1, 8, true)); - assert_eq!(events(), expected_events); - let collator_state = Stake::collator_state2(1).unwrap(); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(5), + 1, + 8 + )); + assert_event_emitted!(Event::DelegationIncreased(5, 1, 8, true)); + let collator_state = ParachainStaking::candidate_info(1).unwrap(); // 18 + 19 + 20 + 21 + 20 = 98 (top 4 + self bond) assert_eq!(collator_state.total_counted, 98); - // 14 + 15 + 16 + 17 = 62 - assert_eq!( - collator_state.total_counted + 62, - collator_state.total_backing - ); // bump bottom to the top - assert_ok!(Stake::nominator_bond_more(Origin::signed(6), 1, 8)); - expected_events.push(Event::NominationIncreased(6, 1, 8, true)); - assert_eq!(events(), expected_events); - let collator_state = Stake::collator_state2(1).unwrap(); + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(6), + 1, + 8 + )); + assert_event_emitted!(Event::DelegationIncreased(6, 1, 8, true)); + let collator_state = ParachainStaking::candidate_info(1).unwrap(); // 19 + 20 + 21 + 22 + 20 = 102 (top 4 + self bond) assert_eq!(collator_state.total_counted, 102); - // 15 + 16 + 17 + 18 = 66 - assert_eq!( - collator_state.total_counted + 66, - collator_state.total_backing - ); }); } #[test] -fn nomination_events_convey_correct_position() { +fn delegation_events_convey_correct_position() { ExtBuilder::default() .with_balances(vec![ (1, 100), @@ -3816,90 +4801,1490 @@ fn nomination_events_convey_correct_position() { (10, 100), ]) .with_candidates(vec![(1, 20), (2, 20)]) - .with_nominations(vec![(3, 1, 11), (4, 1, 12), (5, 1, 13), (6, 1, 14)]) + .with_delegations(vec![(3, 1, 11), (4, 1, 12), (5, 1, 13), (6, 1, 14)]) .build() .execute_with(|| { - let collator1_state = Stake::collator_state2(1).unwrap(); + let collator1_state = ParachainStaking::candidate_info(1).unwrap(); // 11 + 12 + 13 + 14 + 20 = 70 (top 4 + self bond) assert_eq!(collator1_state.total_counted, 70); - assert_eq!(collator1_state.total_counted, collator1_state.total_backing); - // Top nominations are full, new highest nomination is made - assert_ok!(Stake::nominate(Origin::signed(7), 1, 15, 10, 10)); - let mut expected_events = Vec::new(); - expected_events.push(Event::Nomination( + // Top delegations are full, new highest delegation is made + assert_ok!(ParachainStaking::delegate(Origin::signed(7), 1, 15, 10, 10)); + assert_event_emitted!(Event::Delegation( 7, 15, 1, - NominatorAdded::AddedToTop { new_total: 74 }, + DelegatorAdded::AddedToTop { new_total: 74 }, )); - assert_eq!(events(), expected_events); - let collator1_state = Stake::collator_state2(1).unwrap(); + let collator1_state = ParachainStaking::candidate_info(1).unwrap(); // 12 + 13 + 14 + 15 + 20 = 70 (top 4 + self bond) assert_eq!(collator1_state.total_counted, 74); - // 11 = 11 - assert_eq!( - collator1_state.total_counted + 11, - collator1_state.total_backing - ); - // New nomination is added to the bottom - assert_ok!(Stake::nominate(Origin::signed(8), 1, 10, 10, 10)); - expected_events.push(Event::Nomination(8, 10, 1, NominatorAdded::AddedToBottom)); - assert_eq!(events(), expected_events); - let collator1_state = Stake::collator_state2(1).unwrap(); + // New delegation is added to the bottom + assert_ok!(ParachainStaking::delegate(Origin::signed(8), 1, 10, 10, 10)); + assert_event_emitted!(Event::Delegation(8, 10, 1, DelegatorAdded::AddedToBottom)); + let collator1_state = ParachainStaking::candidate_info(1).unwrap(); // 12 + 13 + 14 + 15 + 20 = 70 (top 4 + self bond) assert_eq!(collator1_state.total_counted, 74); - // 10 + 11 = 21 - assert_eq!( - collator1_state.total_counted + 21, - collator1_state.total_backing - ); - // 8 increases nomination to the top - assert_ok!(Stake::nominator_bond_more(Origin::signed(8), 1, 3)); - expected_events.push(Event::NominationIncreased(8, 1, 3, true)); - assert_eq!(events(), expected_events); - let collator1_state = Stake::collator_state2(1).unwrap(); + // 8 increases delegation to the top + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(8), + 1, + 3 + )); + assert_event_emitted!(Event::DelegationIncreased(8, 1, 3, true)); + let collator1_state = ParachainStaking::candidate_info(1).unwrap(); // 13 + 13 + 14 + 15 + 20 = 75 (top 4 + self bond) assert_eq!(collator1_state.total_counted, 75); - // 11 + 12 = 23 - assert_eq!( - collator1_state.total_counted + 23, - collator1_state.total_backing - ); - // 3 increases nomination but stays in bottom - assert_ok!(Stake::nominator_bond_more(Origin::signed(3), 1, 1)); - expected_events.push(Event::NominationIncreased(3, 1, 1, false)); - assert_eq!(events(), expected_events); - let collator1_state = Stake::collator_state2(1).unwrap(); + // 3 increases delegation but stays in bottom + assert_ok!(ParachainStaking::delegator_bond_more( + Origin::signed(3), + 1, + 1 + )); + assert_event_emitted!(Event::DelegationIncreased(3, 1, 1, false)); + let collator1_state = ParachainStaking::candidate_info(1).unwrap(); // 13 + 13 + 14 + 15 + 20 = 75 (top 4 + self bond) assert_eq!(collator1_state.total_counted, 75); - // 12 + 12 = 24 - assert_eq!( - collator1_state.total_counted + 24, - collator1_state.total_backing - ); - // 6 decreases nomination but stays in top - assert_ok!(Stake::nominator_bond_less(Origin::signed(6), 1, 2)); - expected_events.push(Event::NominationDecreased(6, 1, 2, true)); - assert_eq!(events(), expected_events); - let collator1_state = Stake::collator_state2(1).unwrap(); - // 12 + 13 + 13 + 15 + 20 = 73 (top 4 + self bond) + // 6 decreases delegation but stays in top + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(6), + 1, + 2 + )); + assert_event_emitted!(Event::DelegationDecreaseScheduled(6, 1, 2, 3)); + roll_to(30); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(6), + 6, + 1 + )); + assert_event_emitted!(Event::DelegationDecreased(6, 1, 2, true)); + let collator1_state = ParachainStaking::candidate_info(1).unwrap(); + // 12 + 13 + 13 + 15 + 20 = 73 (top 4 + self bond)Æ’ assert_eq!(collator1_state.total_counted, 73); - // 12 + 12 = 24 - assert_eq!( - collator1_state.total_counted + 24, - collator1_state.total_backing - ); - // 6 decreases nomination and is bumped to bottom - assert_ok!(Stake::nominator_bond_less(Origin::signed(6), 1, 1)); - expected_events.push(Event::NominationDecreased(6, 1, 1, false)); - assert_eq!(events(), expected_events); - let collator1_state = Stake::collator_state2(1).unwrap(); + // 6 decreases delegation and is bumped to bottom + assert_ok!(ParachainStaking::schedule_delegator_bond_less( + Origin::signed(6), + 1, + 1 + )); + assert_event_emitted!(Event::DelegationDecreaseScheduled(6, 1, 1, 9)); + roll_to(40); + assert_ok!(ParachainStaking::execute_delegation_request( + Origin::signed(6), + 6, + 1 + )); + assert_event_emitted!(Event::DelegationDecreased(6, 1, 1, false)); + let collator1_state = ParachainStaking::candidate_info(1).unwrap(); // 12 + 13 + 13 + 15 + 20 = 73 (top 4 + self bond) assert_eq!(collator1_state.total_counted, 73); - // 11 + 12 = 23 - assert_eq!( - collator1_state.total_counted + 23, - collator1_state.total_backing + }); +} + +#[test] +fn no_rewards_paid_until_after_reward_payment_delay() { + ExtBuilder::default() + .with_balances(vec![(1, 20), (2, 20), (3, 20), (4, 20)]) + .with_candidates(vec![(1, 20), (2, 20), (3, 20), (4, 20)]) + .build() + .execute_with(|| { + roll_to_round_begin(2); + // payouts for round 1 + set_author(1, 1, 1); + set_author(1, 2, 1); + set_author(1, 3, 1); + set_author(1, 4, 1); + set_author(1, 4, 1); + let mut expected = vec![ + Event::CollatorChosen(2, 1, 20), + Event::CollatorChosen(2, 2, 20), + Event::CollatorChosen(2, 3, 20), + Event::CollatorChosen(2, 4, 20), + Event::NewRound(5, 2, 4, 80), + ]; + assert_eq_events!(expected); + + roll_to_round_begin(3); + expected.append(&mut vec![ + Event::CollatorChosen(3, 1, 20), + Event::CollatorChosen(3, 2, 20), + Event::CollatorChosen(3, 3, 20), + Event::CollatorChosen(3, 4, 20), + Event::NewRound(10, 3, 4, 80), + // rewards will begin immediately following a NewRound + Event::Rewarded(3, 1), + ]); + assert_eq_events!(expected); + + // roll to the next block where we start round 3; we should have round change and first + // payout made. + roll_one_block(); + expected.push(Event::Rewarded(4, 2)); + assert_eq_events!(expected); + + roll_one_block(); + expected.push(Event::Rewarded(1, 1)); + assert_eq_events!(expected); + + roll_one_block(); + expected.push(Event::Rewarded(2, 1)); + assert_eq_events!(expected); + + // there should be no more payments in this round... + let num_blocks_rolled = roll_to_round_end(3); + assert_eq_events!(expected); + assert_eq!(num_blocks_rolled, 1); + }); +} + +#[test] +fn deferred_payment_storage_items_are_cleaned_up() { + use crate::*; + + // this test sets up two collators, gives them points in round one, and focuses on the + // storage over the next several blocks to show that it is properly cleaned up + + ExtBuilder::default() + .with_balances(vec![(1, 20), (2, 20)]) + .with_candidates(vec![(1, 20), (2, 20)]) + .build() + .execute_with(|| { + let mut round: u32 = 1; + set_author(round, 1, 1); + set_author(round, 2, 1); + + // reflects genesis? + assert!(>::contains_key(round, 1)); + assert!(>::contains_key(round, 2)); + + round = 2; + roll_to_round_begin(round.into()); + let mut expected = vec![ + Event::CollatorChosen(round, 1, 20), + Event::CollatorChosen(round, 2, 20), + Event::NewRound(5, round, 2, 40), + ]; + assert_eq_events!(expected); + + // we should have AtStake snapshots as soon as we start a round... + assert!(>::contains_key(2, 1)); + assert!(>::contains_key(2, 2)); + // ...and it should persist until the round is fully paid out + assert!(>::contains_key(1, 1)); + assert!(>::contains_key(1, 2)); + + assert!( + !>::contains_key(1), + "DelayedPayouts shouldn't be populated until after RewardPaymentDelay" + ); + assert!( + >::contains_key(1), + "Points should be populated during current round" + ); + assert!( + >::contains_key(1), + "Staked should be populated when round changes" + ); + + assert!( + !>::contains_key(2), + "Points should not be populated until author noted" + ); + assert!( + >::contains_key(2), + "Staked should be populated when round changes" + ); + + // first payout occurs in round 3 + round = 3; + roll_to_round_begin(round.into()); + expected.append(&mut vec![ + Event::CollatorChosen(round, 1, 20), + Event::CollatorChosen(round, 2, 20), + Event::NewRound(10, round, 2, 40), + Event::Rewarded(1, 1), + ]); + assert_eq_events!(expected); + + // payouts should exist for past rounds that haven't been paid out yet.. + assert!(>::contains_key(3, 1)); + assert!(>::contains_key(3, 2)); + assert!(>::contains_key(2, 1)); + assert!(>::contains_key(2, 2)); + + assert!( + >::contains_key(1), + "DelayedPayouts should be populated after RewardPaymentDelay" + ); + assert!(>::contains_key(1)); + assert!( + !>::contains_key(1), + "Staked should be cleaned up after round change" ); + + assert!(!>::contains_key(2)); + assert!( + !>::contains_key(2), + "We never rewarded points for round 2" + ); + assert!(>::contains_key(2)); + + assert!(!>::contains_key(3)); + assert!( + !>::contains_key(3), + "We never awarded points for round 3" + ); + assert!(>::contains_key(3)); + + // collator 1 has been paid in this last block and associated storage cleaned up + assert!(!>::contains_key(1, 1)); + assert!(!>::contains_key(1, 1)); + + // but collator 2 hasn't been paid + assert!(>::contains_key(1, 2)); + assert!(>::contains_key(1, 2)); + + round = 4; + roll_to_round_begin(round.into()); + expected.append(&mut vec![ + Event::Rewarded(2, 1), // from previous round + Event::CollatorChosen(round, 1, 20), + Event::CollatorChosen(round, 2, 20), + Event::NewRound(15, round, 2, 40), + ]); + assert_eq_events!(expected); + + // collators have both been paid and storage fully cleaned up for round 1 + assert!(!>::contains_key(1, 2)); + assert!(!>::contains_key(1, 2)); + assert!(!>::contains_key(1)); + assert!(!>::contains_key(1)); // points should be cleaned up + assert!(!>::contains_key(1)); + + roll_to_round_end(4); + + // no more events expected + assert_eq_events!(expected); }); } + +#[test] +fn deferred_payment_steady_state_event_flow() { + use frame_support::traits::{Currency, ExistenceRequirement, WithdrawReasons}; + + // this test "flows" through a number of rounds, asserting that certain things do/don't happen + // once the staking pallet is in a "steady state" (specifically, once we are past the first few + // rounds to clear RewardPaymentDelay) + + ExtBuilder::default() + .with_balances(vec![ + // collators + (1, 200), + (2, 200), + (3, 200), + (4, 200), + // delegators + (11, 200), + (22, 200), + (33, 200), + (44, 200), + // burn account, see `reset_issuance()` + (111, 1000), + ]) + .with_candidates(vec![(1, 200), (2, 200), (3, 200), (4, 200)]) + .with_delegations(vec![ + // delegator 11 delegates 100 to 1 and 2 + (11, 1, 100), + (11, 2, 100), + // delegator 22 delegates 100 to 2 and 3 + (22, 2, 100), + (22, 3, 100), + // delegator 33 delegates 100 to 3 and 4 + (33, 3, 100), + (33, 4, 100), + // delegator 44 delegates 100 to 4 and 1 + (44, 4, 100), + (44, 1, 100), + ]) + .build() + .execute_with(|| { + // convenience to set the round points consistently + let set_round_points = |round: u64| { + set_author(round as u32, 1, 1); + set_author(round as u32, 2, 1); + set_author(round as u32, 3, 1); + set_author(round as u32, 4, 1); + }; + + // grab initial issuance -- we will reset it before round issuance is calculated so that + // it is consistent every round + let initial_issuance = Balances::total_issuance(); + let reset_issuance = || { + let new_issuance = Balances::total_issuance(); + let diff = new_issuance - initial_issuance; + let burned = Balances::burn(diff); + Balances::settle( + &111, + burned, + WithdrawReasons::FEE, + ExistenceRequirement::AllowDeath, + ) + .expect("Account can absorb burn"); + }; + + // fn to roll through the first RewardPaymentDelay rounds. returns new round index + let roll_through_initial_rounds = |mut round: u64| -> u64 { + while round < crate::mock::RewardPaymentDelay::get() as u64 + 1 { + set_round_points(round); + + roll_to_round_end(round); + round += 1; + } + + reset_issuance(); + + round + }; + + // roll through a "steady state" round and make all of our assertions + // returns new round index + let roll_through_steady_state_round = |round: u64| -> u64 { + let num_rounds_rolled = roll_to_round_begin(round); + assert_eq!( + num_rounds_rolled, 1, + "expected to be at round begin already" + ); + + let expected = vec![ + Event::CollatorChosen(round as u32, 1, 400), + Event::CollatorChosen(round as u32, 2, 400), + Event::CollatorChosen(round as u32, 3, 400), + Event::CollatorChosen(round as u32, 4, 400), + Event::NewRound((round - 1) * 5, round as u32, 4, 1600), + // first payout should occur on round change + Event::Rewarded(3, 19), + Event::Rewarded(22, 6), + Event::Rewarded(33, 6), + ]; + assert_eq_last_events!(expected); + + set_round_points(round); + + roll_one_block(); + let expected = vec![ + Event::Rewarded(4, 19), + Event::Rewarded(33, 6), + Event::Rewarded(44, 6), + ]; + assert_eq_last_events!(expected); + + roll_one_block(); + let expected = vec![ + Event::Rewarded(1, 19), + Event::Rewarded(11, 6), + Event::Rewarded(44, 6), + ]; + assert_eq_last_events!(expected); + + roll_one_block(); + let expected = vec![ + Event::Rewarded(2, 19), + Event::Rewarded(11, 6), + Event::Rewarded(22, 6), + ]; + assert_eq_last_events!(expected); + + roll_one_block(); + let expected = vec![ + // we paid everyone out by now, should repeat last event + Event::Rewarded(22, 6), + ]; + assert_eq_last_events!(expected); + + let num_rounds_rolled = roll_to_round_end(round); + assert_eq!(num_rounds_rolled, 0, "expected to be at round end already"); + + reset_issuance(); + + round + 1 + }; + + let mut round = 1; + round = roll_through_initial_rounds(round); // we should be at RewardPaymentDelay + for _ in 1..5 { + round = roll_through_steady_state_round(round); + } + }); +} + +// HOTFIX UNIT TESTs + +#[test] +fn hotfix_remove_delegation_requests_works() { + ExtBuilder::default() + .with_balances(vec![(1, 20), (2, 20)]) + .with_candidates(vec![(1, 20)]) + .build() + .execute_with(|| { + let mut requests: BTreeMap< + ::AccountId, + DelegationRequest<::AccountId, BalanceOf>, + > = BTreeMap::new(); + requests.insert( + 3, + DelegationRequest { + collator: 3, + amount: 5, + when_executable: 0, + action: DelegationChange::Decrease, + }, + ); + requests.insert( + 4, + DelegationRequest { + collator: 4, + amount: 20, + when_executable: 0, + action: DelegationChange::Revoke, + }, + ); + let corrupted_delegator_state = Delegator { + id: 2, + delegations: OrderedSet::from(vec![Bond { + owner: 1, + amount: 20, + }]), + total: 20, + requests: PendingDelegationRequests { + revocations_count: 1, + requests, + less_total: 25, + }, + status: DelegatorStatus::Active, + }; + >::insert(2, corrupted_delegator_state); + assert_ok!(ParachainStaking::hotfix_remove_delegation_requests( + Origin::root(), + vec![2, 5] + )); + assert!(ParachainStaking::delegator_state(&5).is_none()); + let fixed_delegator_state = + ParachainStaking::delegator_state(&2).expect("inserted => exists"); + assert_eq!(fixed_delegator_state.requests.revocations_count, 0); + assert_eq!(fixed_delegator_state.requests.less_total, 0); + }); +} + +#[test] +fn hotfix_update_candidate_pool_value_updates_candidate_pool() { + ExtBuilder::default() + .with_balances(vec![(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20)]) + .with_candidates(vec![(1, 20), (2, 20), (3, 20), (4, 20), (5, 20)]) + .build() + .execute_with(|| { + // corrupt CandidatePool + >::put(OrderedSet::from(vec![ + Bond { + owner: 1, + amount: 15, + }, + Bond { + owner: 2, + amount: 16, + }, + Bond { + owner: 3, + amount: 17, + }, + Bond { + owner: 4, + amount: 18, + }, + Bond { + owner: 5, + amount: 19, + }, + ])); + // run migration and pass in 6 even though not a candidate + assert_ok!(ParachainStaking::hotfix_update_candidate_pool_value( + Origin::root(), + vec![1, 2, 3, 4, 5, 6] + )); + // CandidatePool is now fixed for all input accounts + let pool = >::get(); + for Bond { owner, amount } in pool.0 { + // 6 is not in the candidate pool despite being passed in + assert!(owner <= 5 && owner >= 1); + // all amounts are fixed + assert_eq!(amount, 20); + } + }); +} + +// MIGRATION UNIT TESTS +use frame_support::traits::OnRuntimeUpgrade; + +#[test] +/// Kicks extra bottom delegations to force leave delegators if last delegation +fn split_candidate_state_kicks_extra_bottom_delegators_to_exit() { + ExtBuilder::default() + .with_balances(vec![(11, 22), (12, 20)]) + .build() + .execute_with(|| { + for i in 11..13 { + let old_delegator_state = Delegator { + id: i, + delegations: OrderedSet::from(vec![ + Bond { + owner: 1, + amount: 10, + }, + Bond { + owner: 2, + amount: 10, + }, + ]), + total: 20, + requests: PendingDelegationRequests::new(), + status: DelegatorStatus::Active, + }; + >::insert(&i, old_delegator_state); + } + assert_ok!(::Currency::reserve(&11, 22)); + assert_ok!(::Currency::reserve(&12, 20)); + assert_eq!(Balances::reserved_balance(&11), 22); + assert_eq!(Balances::reserved_balance(&12), 20); + for i in 1..3 { + let old_candidate_state = CollatorCandidate { + id: i, + bond: 20, + delegators: OrderedSet::from(vec![3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), + top_delegations: vec![ + Bond { + owner: 3, + amount: 19, + }, + Bond { + owner: 4, + amount: 18, + }, + Bond { + owner: 5, + amount: 17, + }, + Bond { + owner: 6, + amount: 16, + }, + ], + bottom_delegations: vec![ + Bond { + owner: 12, + amount: 10, + }, + Bond { + owner: 11, + amount: 11, + }, + Bond { + owner: 10, + amount: 12, + }, + Bond { + owner: 9, + amount: 13, + }, + Bond { + owner: 8, + amount: 14, + }, + Bond { + owner: 7, + amount: 15, + }, + ], + total_counted: 90, + total_backing: 165, + request: None, + state: CollatorStatus::Active, + }; + >::insert(&i, old_candidate_state); + } + // total is 165 * 2 = 330 + >::put(330); + assert!(ParachainStaking::is_delegator(&11)); + assert!(ParachainStaking::is_delegator(&12)); + crate::migrations::SplitCandidateStateToDecreasePoV::::on_runtime_upgrade(); + assert_event_emitted!(Event::DelegationKicked(11, 1, 11)); + assert_event_emitted!(Event::DelegationKicked(11, 2, 11)); + assert_event_emitted!(Event::DelegationKicked(12, 1, 10)); + assert_event_emitted!(Event::DelegationKicked(12, 2, 10)); + assert_event_emitted!(Event::DelegatorLeft(12, 10)); + assert_event_emitted!(Event::DelegatorLeft(11, 11)); + // kicked 11 and 12 and revoked them + assert_eq!(Balances::free_balance(&11), 22); + assert_eq!(Balances::free_balance(&12), 20); + assert!(!ParachainStaking::is_delegator(&11)); + assert!(!ParachainStaking::is_delegator(&12)); + for i in 1..3 { + let top_delegations = >::get(&i).unwrap(); + assert_eq!(top_delegations.total, 70); + assert_eq!( + top_delegations.delegations, + vec![ + Bond { + owner: 3, + amount: 19 + }, + Bond { + owner: 4, + amount: 18 + }, + Bond { + owner: 5, + amount: 17 + }, + Bond { + owner: 6, + amount: 16 + } + ] + ); + let bottom_delegations = >::get(&i).unwrap(); + assert_eq!(bottom_delegations.total, 54); + assert_eq!( + bottom_delegations.delegations, + vec![ + Bond { + owner: 7, + amount: 15 + }, + Bond { + owner: 8, + amount: 14 + }, + Bond { + owner: 9, + amount: 13 + }, + Bond { + owner: 10, + amount: 12 + } + ] + ); + let candidate_metadata = >::get(&i).unwrap(); + assert_eq!(candidate_metadata.top_capacity, CapacityStatus::Full); + assert_eq!(candidate_metadata.bottom_capacity, CapacityStatus::Full); + assert_eq!(candidate_metadata.lowest_top_delegation_amount, 16); + assert_eq!(candidate_metadata.highest_bottom_delegation_amount, 15); + assert_eq!(candidate_metadata.lowest_bottom_delegation_amount, 12); + } + }); +} + +#[test] +/// Force revokes candidate state +fn split_candidate_state_kicks_extra_bottom_delegations_without_exit() { + ExtBuilder::default() + .with_balances(vec![(11, 32), (12, 30)]) + .build() + .execute_with(|| { + for i in 11..13 { + let old_delegator_state = Delegator { + id: i, + delegations: OrderedSet::from(vec![ + Bond { + owner: 1, + amount: 10, + }, + Bond { + owner: 2, + amount: 10, + }, + Bond { + owner: 3, + amount: 10, + }, + ]), + total: 30, + requests: PendingDelegationRequests::new(), + status: DelegatorStatus::Active, + }; + >::insert(&i, old_delegator_state); + } + assert_ok!(::Currency::reserve(&11, 32)); + assert_ok!(::Currency::reserve(&12, 30)); + assert_eq!(Balances::reserved_balance(&11), 32); + assert_eq!(Balances::reserved_balance(&12), 30); + for i in 1..3 { + let old_candidate_state = CollatorCandidate { + id: i, + bond: 20, + delegators: OrderedSet::from(vec![3, 4, 5, 6, 7, 8, 9, 10, 11, 12]), + top_delegations: vec![ + Bond { + owner: 3, + amount: 19, + }, + Bond { + owner: 4, + amount: 18, + }, + Bond { + owner: 5, + amount: 17, + }, + Bond { + owner: 6, + amount: 16, + }, + ], + bottom_delegations: vec![ + Bond { + owner: 12, + amount: 10, + }, + Bond { + owner: 11, + amount: 11, + }, + Bond { + owner: 10, + amount: 12, + }, + Bond { + owner: 9, + amount: 13, + }, + Bond { + owner: 8, + amount: 14, + }, + Bond { + owner: 7, + amount: 15, + }, + ], + total_counted: 90, + total_backing: 165, + request: None, + state: CollatorStatus::Active, + }; + >::insert(&i, old_candidate_state); + } + // total is 165 * 2 + 20 = 330 + >::put(350); + assert!(ParachainStaking::is_delegator(&11)); + assert!(ParachainStaking::is_delegator(&12)); + crate::migrations::SplitCandidateStateToDecreasePoV::::on_runtime_upgrade(); + assert_event_emitted!(Event::DelegationKicked(11, 1, 11)); + assert_event_emitted!(Event::DelegationKicked(11, 2, 11)); + assert_event_emitted!(Event::DelegationKicked(12, 1, 10)); + assert_event_emitted!(Event::DelegationKicked(12, 2, 10)); + assert_event_not_emitted!(Event::DelegatorLeft(12, 10)); + assert_event_not_emitted!(Event::DelegatorLeft(11, 10)); + // kicked 11 and 12 and revoked them + assert_eq!(Balances::free_balance(&11), 22); + assert_eq!(Balances::free_balance(&12), 20); + assert_eq!(Balances::reserved_balance(&11), 10); + assert_eq!(Balances::reserved_balance(&12), 10); + assert!(ParachainStaking::is_delegator(&11)); + assert!(ParachainStaking::is_delegator(&12)); + for i in 1..3 { + let top_delegations = >::get(&i).unwrap(); + assert_eq!(top_delegations.total, 70); + assert_eq!( + top_delegations.delegations, + vec![ + Bond { + owner: 3, + amount: 19 + }, + Bond { + owner: 4, + amount: 18 + }, + Bond { + owner: 5, + amount: 17 + }, + Bond { + owner: 6, + amount: 16 + } + ] + ); + let bottom_delegations = >::get(&i).unwrap(); + assert_eq!(bottom_delegations.total, 54); + assert_eq!( + bottom_delegations.delegations, + vec![ + Bond { + owner: 7, + amount: 15 + }, + Bond { + owner: 8, + amount: 14 + }, + Bond { + owner: 9, + amount: 13 + }, + Bond { + owner: 10, + amount: 12 + } + ] + ); + let candidate_metadata = >::get(&i).unwrap(); + assert_eq!(candidate_metadata.top_capacity, CapacityStatus::Full); + assert_eq!(candidate_metadata.bottom_capacity, CapacityStatus::Full); + assert_eq!(candidate_metadata.lowest_top_delegation_amount, 16); + assert_eq!(candidate_metadata.highest_bottom_delegation_amount, 15); + assert_eq!(candidate_metadata.lowest_bottom_delegation_amount, 12); + } + }); +} + +#[test] +fn split_candidate_state_migrates_empty_delegations_correctly() { + ExtBuilder::default() + // .with_balances(vec![(1, 20), (2, 20), (3, 20), (4, 20)]) + // .with_candidates(vec![(1, 20), (2, 20), (3, 20), (4, 20)]) + .build() + .execute_with(|| { + // set candidate state as per commented out lines above + for i in 1..5 { + let old_candidate_state = CollatorCandidate { + id: i, + bond: 20, + delegators: OrderedSet::new(), + top_delegations: Vec::new(), + bottom_delegations: Vec::new(), + total_counted: 20, + total_backing: 20, + request: None, + state: CollatorStatus::Active, + }; + >::insert(&i, old_candidate_state); + } + crate::migrations::SplitCandidateStateToDecreasePoV::::on_runtime_upgrade(); + for i in 1..5 { + let top_delegations = >::get(&i).unwrap(); + assert_eq!(top_delegations.total, 0); + assert!(top_delegations.delegations.is_empty()); + let bottom_delegations = >::get(&i).unwrap(); + assert_eq!(bottom_delegations.total, 0); + assert!(bottom_delegations.delegations.is_empty()); + let candidate_metadata = >::get(&i).unwrap(); + assert_eq!(candidate_metadata.top_capacity, CapacityStatus::Empty); + assert_eq!(candidate_metadata.bottom_capacity, CapacityStatus::Empty); + assert_eq!(candidate_metadata.lowest_top_delegation_amount, 0); + assert_eq!(candidate_metadata.highest_bottom_delegation_amount, 0); + assert_eq!(candidate_metadata.lowest_bottom_delegation_amount, 0); + } + }); +} + +#[test] +fn split_candidate_state_migrates_partial_top_delegations_correctly() { + ExtBuilder::default() + // .with_balances(vec![(1, 20), (2, 20), (3, 20), (4, 20)]) + // .with_candidates(vec![(1, 20), (2, 20)]) + // .with_delegations(vec![(3, 1, 10), (4, 1, 10), (3, 2, 10), (4, 2, 10)]) + .build() + .execute_with(|| { + // set up candidate state as per commented out lines above + for i in 1..3 { + let old_candidate_state = CollatorCandidate { + id: i, + bond: 20, + delegators: OrderedSet::from(vec![3, 4]), + top_delegations: vec![ + Bond { + owner: 3, + amount: 10, + }, + Bond { + owner: 4, + amount: 10, + }, + ], + bottom_delegations: Vec::new(), + total_counted: 40, + total_backing: 40, + request: None, + state: CollatorStatus::Active, + }; + >::insert(&i, old_candidate_state); + } + crate::migrations::SplitCandidateStateToDecreasePoV::::on_runtime_upgrade(); + for i in 1..3 { + let top_delegations = >::get(&i).unwrap(); + assert_eq!(top_delegations.total, 20); + assert_eq!( + top_delegations.delegations, + vec![ + Bond { + owner: 3, + amount: 10 + }, + Bond { + owner: 4, + amount: 10 + } + ] + ); + let bottom_delegations = >::get(&i).unwrap(); + assert_eq!(bottom_delegations.total, 0); + assert!(bottom_delegations.delegations.is_empty()); + let candidate_metadata = >::get(&i).unwrap(); + assert_eq!(candidate_metadata.top_capacity, CapacityStatus::Partial); + assert_eq!(candidate_metadata.bottom_capacity, CapacityStatus::Empty); + assert_eq!(candidate_metadata.lowest_top_delegation_amount, 10); + assert_eq!(candidate_metadata.highest_bottom_delegation_amount, 0); + assert_eq!(candidate_metadata.lowest_bottom_delegation_amount, 0); + } + }); +} + +#[test] +fn split_candidate_state_migrates_full_top_delegations_correctly() { + ExtBuilder::default() + // .with_balances(vec![(1, 20), (2, 20), (3, 20), (4, 20), (5, 20), (6, 20)]) + // .with_candidates(vec![(1, 20), (2, 20)]) + // .with_delegations(vec![ + // (3, 1, 10), + // (4, 1, 10), + // (5, 1, 10), + // (6, 1, 10), + // (3, 2, 10), + // (4, 2, 10), + // (5, 2, 10), + // (6, 2, 10), + // ]) + .build() + .execute_with(|| { + // set up candidate state as per commented out lines + for i in 1..3 { + let old_candidate_state = CollatorCandidate { + id: i, + bond: 20, + delegators: OrderedSet::from(vec![3, 4, 5, 6]), + top_delegations: vec![ + Bond { + owner: 3, + amount: 10, + }, + Bond { + owner: 4, + amount: 10, + }, + Bond { + owner: 5, + amount: 10, + }, + Bond { + owner: 6, + amount: 10, + }, + ], + bottom_delegations: Vec::new(), + total_counted: 60, + total_backing: 60, + request: None, + state: CollatorStatus::Active, + }; + >::insert(&i, old_candidate_state); + } + crate::migrations::SplitCandidateStateToDecreasePoV::::on_runtime_upgrade(); + for i in 1..3 { + let top_delegations = >::get(&i).unwrap(); + assert_eq!(top_delegations.total, 40); + assert_eq!( + top_delegations.delegations, + vec![ + Bond { + owner: 3, + amount: 10 + }, + Bond { + owner: 4, + amount: 10 + }, + Bond { + owner: 5, + amount: 10 + }, + Bond { + owner: 6, + amount: 10 + } + ] + ); + let bottom_delegations = >::get(&i).unwrap(); + assert_eq!(bottom_delegations.total, 0); + assert!(bottom_delegations.delegations.is_empty()); + let candidate_metadata = >::get(&i).unwrap(); + assert_eq!(candidate_metadata.top_capacity, CapacityStatus::Full); + assert_eq!(candidate_metadata.bottom_capacity, CapacityStatus::Empty); + assert_eq!(candidate_metadata.lowest_top_delegation_amount, 10); + assert_eq!(candidate_metadata.highest_bottom_delegation_amount, 0); + assert_eq!(candidate_metadata.lowest_bottom_delegation_amount, 0); + } + }); +} + +#[test] +fn split_candidate_state_migrates_full_top_partial_bottom_delegations_correctly() { + ExtBuilder::default() + // .with_balances(vec![ + // (1, 20), + // (2, 20), + // (3, 38), + // (4, 36), + // (5, 34), + // (6, 32), + // (7, 30), + // (8, 28), + // ]) + // .with_candidates(vec![(1, 20), (2, 20)]) + // .with_delegations(vec![ + // (3, 1, 19), + // (4, 1, 18), + // (5, 1, 17), + // (6, 1, 16), + // (7, 1, 15), + // (8, 1, 14), + // (3, 2, 19), + // (4, 2, 18), + // (5, 2, 17), + // (6, 2, 16), + // (7, 2, 15), + // (8, 2, 14), + // ]) + .build() + .execute_with(|| { + // set up candidate state as per commented out lines + for i in 1..3 { + let old_candidate_state = CollatorCandidate { + id: i, + bond: 20, + delegators: OrderedSet::from(vec![3, 4, 5, 6, 7, 8]), + top_delegations: vec![ + Bond { + owner: 3, + amount: 19, + }, + Bond { + owner: 4, + amount: 18, + }, + Bond { + owner: 5, + amount: 17, + }, + Bond { + owner: 6, + amount: 16, + }, + ], + bottom_delegations: vec![ + Bond { + owner: 8, + amount: 14, + }, + Bond { + owner: 7, + amount: 15, + }, + ], + total_counted: 90, + total_backing: 119, + request: None, + state: CollatorStatus::Active, + }; + >::insert(&i, old_candidate_state); + } + crate::migrations::SplitCandidateStateToDecreasePoV::::on_runtime_upgrade(); + for i in 1..3 { + let top_delegations = >::get(&i).unwrap(); + assert_eq!(top_delegations.total, 70); + assert_eq!( + top_delegations.delegations, + vec![ + Bond { + owner: 3, + amount: 19 + }, + Bond { + owner: 4, + amount: 18 + }, + Bond { + owner: 5, + amount: 17 + }, + Bond { + owner: 6, + amount: 16 + } + ] + ); + let bottom_delegations = >::get(&i).unwrap(); + assert_eq!(bottom_delegations.total, 29); + assert_eq!( + bottom_delegations.delegations, + vec![ + Bond { + owner: 7, + amount: 15 + }, + Bond { + owner: 8, + amount: 14 + } + ] + ); + let candidate_metadata = >::get(&i).unwrap(); + assert_eq!(candidate_metadata.top_capacity, CapacityStatus::Full); + assert_eq!(candidate_metadata.bottom_capacity, CapacityStatus::Partial); + assert_eq!(candidate_metadata.lowest_top_delegation_amount, 16); + assert_eq!(candidate_metadata.highest_bottom_delegation_amount, 15); + assert_eq!(candidate_metadata.lowest_bottom_delegation_amount, 14); + } + }); +} + +#[test] +fn split_candidate_state_migrates_full_top_and_bottom_delegations_correctly() { + ExtBuilder::default() + // .with_balances(vec![ + // (1, 20), + // (2, 20), + // (3, 38), + // (4, 36), + // (5, 34), + // (6, 32), + // (7, 30), + // (8, 28), + // (9, 26), + // (10, 24), + // ]) + // .with_candidates(vec![(1, 20), (2, 20)]) + // .with_delegations(vec![ + // (3, 1, 19), + // (4, 1, 18), + // (5, 1, 17), + // (6, 1, 16), + // (7, 1, 15), + // (8, 1, 14), + // (9, 1, 13), + // (10, 1, 12), + // (3, 2, 19), + // (4, 2, 18), + // (5, 2, 17), + // (6, 2, 16), + // (7, 2, 15), + // (8, 2, 14), + // (9, 2, 13), + // (10, 2, 12), + // ]) + .build() + .execute_with(|| { + // set up candidate state as per commented out lines + for i in 1..3 { + let old_candidate_state = CollatorCandidate { + id: i, + bond: 20, + delegators: OrderedSet::from(vec![3, 4, 5, 6, 7, 8, 9, 10]), + top_delegations: vec![ + Bond { + owner: 3, + amount: 19, + }, + Bond { + owner: 4, + amount: 18, + }, + Bond { + owner: 5, + amount: 17, + }, + Bond { + owner: 6, + amount: 16, + }, + ], + bottom_delegations: vec![ + Bond { + owner: 10, + amount: 12, + }, + Bond { + owner: 9, + amount: 13, + }, + Bond { + owner: 8, + amount: 14, + }, + Bond { + owner: 7, + amount: 15, + }, + ], + total_counted: 90, + total_backing: 144, + request: None, + state: CollatorStatus::Active, + }; + >::insert(&i, old_candidate_state); + } + crate::migrations::SplitCandidateStateToDecreasePoV::::on_runtime_upgrade(); + for i in 1..3 { + let top_delegations = >::get(&i).unwrap(); + assert_eq!(top_delegations.total, 70); + assert_eq!( + top_delegations.delegations, + vec![ + Bond { + owner: 3, + amount: 19 + }, + Bond { + owner: 4, + amount: 18 + }, + Bond { + owner: 5, + amount: 17 + }, + Bond { + owner: 6, + amount: 16 + } + ] + ); + let bottom_delegations = >::get(&i).unwrap(); + assert_eq!(bottom_delegations.total, 54); + assert_eq!( + bottom_delegations.delegations, + vec![ + Bond { + owner: 7, + amount: 15 + }, + Bond { + owner: 8, + amount: 14 + }, + Bond { + owner: 9, + amount: 13 + }, + Bond { + owner: 10, + amount: 12 + } + ] + ); + let candidate_metadata = >::get(&i).unwrap(); + assert_eq!(candidate_metadata.top_capacity, CapacityStatus::Full); + assert_eq!(candidate_metadata.bottom_capacity, CapacityStatus::Full); + assert_eq!(candidate_metadata.lowest_top_delegation_amount, 16); + assert_eq!(candidate_metadata.highest_bottom_delegation_amount, 15); + assert_eq!(candidate_metadata.lowest_bottom_delegation_amount, 12); + } + }); +} + +// #[test] +// fn remove_exit_queue_migration_migrates_leaving_candidates() { +// use crate::pallet::ExitQueue2; +// use crate::set::*; +// use crate::*; +// ExtBuilder::default() +// .with_balances(vec![(1, 20), (2, 20), (3, 20), (4, 20), (5, 20)]) +// .with_candidates(vec![(1, 20), (2, 20), (3, 20), (4, 20), (5, 20)]) +// .build() +// .execute_with(|| { +// // prepare leaving state for all 5 candidates before the migration +// for i in 1..6 { +// // manually change the CollatorState2 status +// >::insert( +// i, +// Collator2 { +// id: i, +// bond: 20, +// nominators: OrderedSet::new(), +// top_nominators: Vec::new(), +// bottom_nominators: Vec::new(), +// total_counted: 20, +// total_backing: 20, +// // set to leaving +// state: CollatorStatus::Leaving(3), +// }, +// ); +// } +// >::put(ExitQ { +// candidates: OrderedSet(vec![1, 2, 3, 4, 5]), +// candidate_schedule: vec![(1, 3), (2, 3), (3, 3), (4, 3), (5, 3)], +// ..Default::default() +// }); +// // execute migration +// migrations::RemoveExitQueue::::on_runtime_upgrade(); +// // check expected candidate state reflects previous state +// for i in 1..6 { +// assert!(>::get(i).is_none()); +// assert_eq!( +// >::get(i).unwrap().state, +// CollatorStatus::Leaving(3) +// ); +// } +// // exit queue should be empty +// assert_eq!(>::get(), ExitQ::default()); +// }); +// } + +// #[test] +// fn remove_exit_queue_migration_migrates_leaving_delegators() { +// use crate::pallet::ExitQueue2; +// use crate::set::*; +// use crate::*; +// ExtBuilder::default() +// .with_balances(vec![(2, 100), (3, 100), (4, 100), (5, 100), (6, 100)]) +// .with_candidates(vec![(2, 20)]) +// .with_delegations(vec![(3, 1, 10), (4, 1, 10), (5, 1, 10), (6, 1, 10)]) +// .build() +// .execute_with(|| { +// // prepare leaving state for all 4 delegators before the migration +// for i in 3..7 { +// >::insert( +// i, +// Nominator2 { +// delegations: OrderedSet(vec![Bond { +// owner: 1, +// amount: 10, +// }]), +// revocations: OrderedSet::new(), +// total: 10, +// scheduled_revocations_count: 0u32, +// scheduled_revocations_total: 0u32.into(), +// status: DelegatorStatus::Leaving(3), +// }, +// ); +// } +// >::put(ExitQ { +// nominators_leaving: OrderedSet(vec![3, 4, 5, 6]), +// nominator_schedule: vec![(3, None, 3), (4, None, 3), (5, None, 3), (6, None, 3)], +// ..Default::default() +// }); +// // execute migration +// migrations::RemoveExitQueue::::on_runtime_upgrade(); +// // check expected delegator state reflects previous state +// for i in 3..7 { +// assert!(>::get(i).is_none()); +// assert_eq!( +// ParachainStaking::delegator_state(i).unwrap().status, +// DelegatorStatus::Leaving(3) +// ); +// } +// // exit queue should be empty +// assert_eq!(>::get(), ExitQ::default()); +// }); +// } + +// #[test] +// fn remove_exit_queue_migration_migrates_delegator_revocations() { +// use crate::pallet::ExitQueue2; +// use crate::set::*; +// use crate::*; +// ExtBuilder::default() +// .with_balances(vec![(2, 100), (3, 100), (4, 100), (5, 100), (6, 100)]) +// .with_candidates(vec![(2, 20)]) +// .with_delegations(vec![(3, 1, 10), (4, 1, 10), (5, 1, 10), (6, 1, 10)]) +// .build() +// .execute_with(|| { +// // prepare leaving state for all 4 delegators before the migration +// for i in 3..7 { +// >::insert( +// i, +// Nominator2 { +// delegations: OrderedSet(vec![Bond { +// owner: 1, +// amount: 10, +// }]), +// revocations: OrderedSet(vec![1]), +// total: 10, +// scheduled_revocations_count: 1u32, +// scheduled_revocations_total: 10u32.into(), +// status: DelegatorStatus::Active, +// }, +// ); +// } +// >::put(ExitQ { +// nominator_schedule: vec![ +// (3, Some(1), 3), +// (4, Some(1), 3), +// (5, Some(1), 3), +// (6, Some(1), 3), +// ], +// ..Default::default() +// }); +// // execute migration +// migrations::RemoveExitQueue::::on_runtime_upgrade(); +// // check expected delegator state reflects previous state +// for i in 3..7 { +// assert!(>::get(i).is_none()); +// assert_eq!( +// ParachainStaking::delegator_state(i) +// .unwrap() +// .requests +// .requests +// .get(&1), +// Some(&DelegationRequest { +// collator: 1, +// amount: 10, +// when_executable: 3, +// action: DelegationChange::Revoke +// }) +// ); +// } +// // exit queue should be empty +// assert_eq!(>::get(), ExitQ::default()); +// }); +// } + +#[test] +fn verify_purge_storage_migration_works() { + use crate::{Points, Round, RoundInfo, Staked}; + ExtBuilder::default().build().execute_with(|| { + // mutate storage similar to if 10 rounds had passed + for i in 1..=10 { + >::insert(i, 100); + >::insert(i, 100); + } + // set the round information to the 10th round + // (we do not use roll_to because the payment logic uses `take` in the code) + >::put(RoundInfo { + current: 10, + first: 45, + length: 5, + }); + // execute the migration + crate::migrations::PurgeStaleStorage::::on_runtime_upgrade(); + // verify that all inserted items are removed except last 2 rounds + for i in 1..=8 { + assert_eq!(>::get(i), 0); + assert_eq!(>::get(i), 0); + } + // last 2 rounds are still stored (necessary for future payouts) + for i in 9..=10 { + assert_eq!(>::get(i), 100); + assert_eq!(>::get(i), 100); + } + }); +} diff --git a/pallets/parachain-staking/src/weights.rs b/pallets/parachain-staking/src/weights.rs index 91665366..e183605e 100644 --- a/pallets/parachain-staking/src/weights.rs +++ b/pallets/parachain-staking/src/weights.rs @@ -1,4 +1,4 @@ -// Copyright 2019-2021 PureStake Inc. +// Copyright 2019-2022 PureStake Inc. // This file is part of Moonbeam. // Moonbeam is free software: you can redistribute it and/or modify @@ -51,6 +51,8 @@ use sp_std::marker::PhantomData; /// Weight functions needed for parachain_staking. pub trait WeightInfo { + fn hotfix_remove_delegation_requests(x: u32) -> Weight; + fn hotfix_update_candidate_pool_value(x: u32) -> Weight; fn set_staking_expectations() -> Weight; fn set_inflation() -> Weight; fn set_parachain_bond_account() -> Weight; @@ -59,23 +61,46 @@ pub trait WeightInfo { fn set_collator_commission() -> Weight; fn set_blocks_per_round() -> Weight; fn join_candidates(x: u32) -> Weight; - fn leave_candidates(x: u32) -> Weight; + fn schedule_leave_candidates(x: u32) -> Weight; + fn execute_leave_candidates(x: u32) -> Weight; + fn cancel_leave_candidates(x: u32) -> Weight; fn go_offline() -> Weight; fn go_online() -> Weight; fn candidate_bond_more() -> Weight; - fn candidate_bond_less() -> Weight; - fn nominate(x: u32, y: u32) -> Weight; - fn leave_nominators(x: u32) -> Weight; - fn revoke_nomination() -> Weight; - fn nominator_bond_more() -> Weight; - fn nominator_bond_less() -> Weight; - fn active_on_initialize(x: u32, y: u32) -> Weight; - fn passive_on_initialize() -> Weight; + fn schedule_candidate_bond_less() -> Weight; + fn execute_candidate_bond_less() -> Weight; + fn cancel_candidate_bond_less() -> Weight; + fn delegate(x: u32, y: u32) -> Weight; + fn schedule_leave_delegators() -> Weight; + fn execute_leave_delegators(x: u32) -> Weight; + fn cancel_leave_delegators() -> Weight; + fn schedule_revoke_delegation() -> Weight; + fn delegator_bond_more() -> Weight; + fn schedule_delegator_bond_less() -> Weight; + fn execute_revoke_delegation() -> Weight; + fn execute_delegator_bond_less() -> Weight; + fn cancel_revoke_delegation() -> Weight; + fn cancel_delegator_bond_less() -> Weight; + fn round_transition_on_initialize(x: u32, y: u32) -> Weight; + fn base_on_initialize() -> Weight; + fn pay_one_collator_reward(y: u32) -> Weight; } /// Weights for parachain_staking using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { + fn hotfix_remove_delegation_requests(x: u32) -> Weight { + (0 as Weight) // Standard Error: 3_000 + .saturating_add((8_132_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(x as Weight))) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(x as Weight))) + } + fn hotfix_update_candidate_pool_value(x: u32) -> Weight { + (0 as Weight) // Standard Error: 147_000 + .saturating_add((26_825_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(x as Weight))) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } fn set_staking_expectations() -> Weight { (20_719_000 as Weight) .saturating_add(T::DbWeight::get().reads(5 as Weight)) @@ -112,91 +137,159 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn join_candidates(x: u32) -> Weight { - (84_807_000 as Weight) - // Standard Error: 1_000 - .saturating_add((333_000 as Weight).saturating_mul(x as Weight)) + (80_619_000 as Weight) // Standard Error: 1_000 + .saturating_add((107_000 as Weight).saturating_mul(x as Weight)) .saturating_add(T::DbWeight::get().reads(9 as Weight)) - .saturating_add(T::DbWeight::get().writes(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) } - fn leave_candidates(x: u32) -> Weight { - (64_426_000 as Weight) - // Standard Error: 1_000 - .saturating_add((332_000 as Weight).saturating_mul(x as Weight)) + fn schedule_leave_candidates(x: u32) -> Weight { + (50_933_000 as Weight) // Standard Error: 1_000 + .saturating_add((108_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn execute_leave_candidates(x: u32) -> Weight { + (8_634_000 as Weight) // Standard Error: 6_000 + .saturating_add((26_979_000 as Weight).saturating_mul(x as Weight)) .saturating_add(T::DbWeight::get().reads(8 as Weight)) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(x as Weight))) .saturating_add(T::DbWeight::get().writes(5 as Weight)) + .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(x as Weight))) + } + fn cancel_leave_candidates(x: u32) -> Weight { + (43_482_000 as Weight) // Standard Error: 0 + .saturating_add((111_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn go_offline() -> Weight { - (36_577_000 as Weight) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) + (30_778_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn go_online() -> Weight { - (36_134_000 as Weight) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) + (31_178_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } fn candidate_bond_more() -> Weight { - (59_735_000 as Weight) + (53_492_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } - fn candidate_bond_less() -> Weight { - (59_421_000 as Weight) - .saturating_add(T::DbWeight::get().reads(8 as Weight)) - .saturating_add(T::DbWeight::get().writes(6 as Weight)) + fn schedule_candidate_bond_less() -> Weight { + (29_393_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - fn nominate(x: u32, y: u32) -> Weight { - (71_656_000 as Weight) - // Standard Error: 1_000 - .saturating_add((1_049_000 as Weight).saturating_mul(x as Weight)) - // Standard Error: 5_000 - .saturating_add((947_000 as Weight).saturating_mul(y as Weight)) + fn execute_candidate_bond_less() -> Weight { + (62_395_000 as Weight) .saturating_add(T::DbWeight::get().reads(9 as Weight)) - .saturating_add(T::DbWeight::get().writes(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) } - fn leave_nominators(x: u32) -> Weight { - (36_354_000 as Weight) - // Standard Error: 2_000 - .saturating_add((694_000 as Weight).saturating_mul(x as Weight)) - .saturating_add(T::DbWeight::get().reads(7 as Weight)) - .saturating_add(T::DbWeight::get().writes(4 as Weight)) + fn cancel_candidate_bond_less() -> Weight { + (25_564_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn delegate(x: u32, y: u32) -> Weight { + (103_760_000 as Weight) // Standard Error: 12_000 + .saturating_add((198_000 as Weight).saturating_mul(x as Weight)) // Standard Error: 3000 + .saturating_add((112_000 as Weight).saturating_mul(y as Weight)) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + } + fn schedule_leave_delegators() -> Weight { + (30_908_000 as Weight) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + } + fn execute_leave_delegators(x: u32) -> Weight { + (1_091_000 as Weight) // Standard Error: 14_000 + .saturating_add((37_192_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(T::DbWeight::get().reads(6 as Weight)) + .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(x as Weight))) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) + .saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(x as Weight))) + } + fn cancel_leave_delegators() -> Weight { + (26_796_000 as Weight) + .saturating_add(T::DbWeight::get().reads(5 as Weight)) + .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - fn revoke_nomination() -> Weight { + fn schedule_revoke_delegation() -> Weight { (37_580_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } - fn nominator_bond_more() -> Weight { - (70_867_000 as Weight) + fn delegator_bond_more() -> Weight { + (65_757_000 as Weight) .saturating_add(T::DbWeight::get().reads(9 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } - fn nominator_bond_less() -> Weight { - (70_857_000 as Weight) + fn schedule_delegator_bond_less() -> Weight { + (70_859_000 as Weight) .saturating_add(T::DbWeight::get().reads(9 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } - // If this takes up too much block space, run again on code - // - #743 benchmarks post reward payout optimization were 3x lower per collator, - // 15x lower per nominator - fn active_on_initialize(x: u32, y: u32) -> Weight { - (0 as Weight) - // Standard Error: 299_000 - .saturating_add((208_550_000 as Weight).saturating_mul(x as Weight)) - // Standard Error: 27_000 - .saturating_add((15_580_000 as Weight).saturating_mul(y as Weight)) - .saturating_add(T::DbWeight::get().reads(26 as Weight)) + fn execute_revoke_delegation() -> Weight { + (87_836_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(7 as Weight)) + } + fn execute_delegator_bond_less() -> Weight { + (80_983_000 as Weight) + .saturating_add(T::DbWeight::get().reads(11 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + } + fn cancel_revoke_delegation() -> Weight { + (37_923_000 as Weight) + .saturating_add(T::DbWeight::get().reads(7 as Weight)) + .saturating_add(T::DbWeight::get().writes(4 as Weight)) + } + fn cancel_delegator_bond_less() -> Weight { + (70_813_000 as Weight) + .saturating_add(T::DbWeight::get().reads(9 as Weight)) + .saturating_add(T::DbWeight::get().writes(7 as Weight)) + } + fn round_transition_on_initialize(x: u32, y: u32) -> Weight { + (0 as Weight) // Standard Error: 4_087_000 + // Standard Error: 12_000 + .saturating_add((100_164_000 as Weight).saturating_mul(x as Weight)) + .saturating_add((1_202_000 as Weight).saturating_mul(y as Weight)) .saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(x as Weight))) - .saturating_add(T::DbWeight::get().writes(16 as Weight)) - .saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(x as Weight))) + .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(x as Weight))) } - fn passive_on_initialize() -> Weight { + fn base_on_initialize() -> Weight { (4_913_000 as Weight).saturating_add(T::DbWeight::get().reads(1 as Weight)) } + fn pay_one_collator_reward(y: u32) -> Weight { + (0 as Weight) + // Standard Error: 6_000 + .saturating_add((23_284_000 as Weight).saturating_mul(y as Weight)) + .saturating_add(T::DbWeight::get().reads(11 as Weight)) + .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(y as Weight))) + .saturating_add(T::DbWeight::get().writes(6 as Weight)) + .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(y as Weight))) + } } // For backwards compatibility and tests impl WeightInfo for () { + fn hotfix_remove_delegation_requests(x: u32) -> Weight { + (0 as Weight) // Standard Error: 3_000 + .saturating_add((8_132_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(x as Weight))) + .saturating_add( + RocksDbWeight::get().writes((1 as Weight).saturating_mul(x as Weight)), + ) + } + fn hotfix_update_candidate_pool_value(x: u32) -> Weight { + (0 as Weight) // Standard Error: 147_000 + .saturating_add((26_825_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(x as Weight))) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } fn set_staking_expectations() -> Weight { (20_719_000 as Weight) .saturating_add(RocksDbWeight::get().reads(5 as Weight)) @@ -233,87 +326,147 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } fn join_candidates(x: u32) -> Weight { - (84_807_000 as Weight) - // Standard Error: 1_000 - .saturating_add((333_000 as Weight).saturating_mul(x as Weight)) + (80_619_000 as Weight) // Standard Error: 1_000 + .saturating_add((107_000 as Weight).saturating_mul(x as Weight)) .saturating_add(RocksDbWeight::get().reads(9 as Weight)) - .saturating_add(RocksDbWeight::get().writes(6 as Weight)) + .saturating_add(RocksDbWeight::get().writes(8 as Weight)) } - fn leave_candidates(x: u32) -> Weight { - (64_426_000 as Weight) - // Standard Error: 1_000 - .saturating_add((332_000 as Weight).saturating_mul(x as Weight)) + fn schedule_leave_candidates(x: u32) -> Weight { + (50_933_000 as Weight) // Standard Error: 1_000 + .saturating_add((108_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(RocksDbWeight::get().reads(7 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + fn execute_leave_candidates(x: u32) -> Weight { + (8_634_000 as Weight) // Standard Error: 6_000 + .saturating_add((26_979_000 as Weight).saturating_mul(x as Weight)) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) + .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(x as Weight))) .saturating_add(RocksDbWeight::get().writes(5 as Weight)) + .saturating_add( + RocksDbWeight::get().writes((2 as Weight).saturating_mul(x as Weight)), + ) + } + fn cancel_leave_candidates(x: u32) -> Weight { + (43_482_000 as Weight) // Standard Error: 0 + .saturating_add((111_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } fn go_offline() -> Weight { - (36_577_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(7 as Weight)) + (30_778_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } fn go_online() -> Weight { - (36_134_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(7 as Weight)) + (31_178_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } fn candidate_bond_more() -> Weight { - (59_735_000 as Weight) + (53_492_000 as Weight) .saturating_add(RocksDbWeight::get().reads(8 as Weight)) .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } - fn candidate_bond_less() -> Weight { - (59_421_000 as Weight) - .saturating_add(RocksDbWeight::get().reads(8 as Weight)) - .saturating_add(RocksDbWeight::get().writes(6 as Weight)) + fn schedule_candidate_bond_less() -> Weight { + (29_393_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } - fn nominate(x: u32, y: u32) -> Weight { - (71_656_000 as Weight) - // Standard Error: 1_000 - .saturating_add((1_049_000 as Weight).saturating_mul(x as Weight)) - // Standard Error: 5_000 - .saturating_add((947_000 as Weight).saturating_mul(y as Weight)) + fn execute_candidate_bond_less() -> Weight { + (62_395_000 as Weight) .saturating_add(RocksDbWeight::get().reads(9 as Weight)) - .saturating_add(RocksDbWeight::get().writes(7 as Weight)) + .saturating_add(RocksDbWeight::get().writes(6 as Weight)) } - fn leave_nominators(x: u32) -> Weight { - (36_354_000 as Weight) - // Standard Error: 2_000 - .saturating_add((694_000 as Weight).saturating_mul(x as Weight)) - .saturating_add(RocksDbWeight::get().reads(7 as Weight)) - .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + fn cancel_candidate_bond_less() -> Weight { + (25_564_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } - fn revoke_nomination() -> Weight { + fn delegate(x: u32, y: u32) -> Weight { + (103_760_000 as Weight) // Standard Error: 12_000 + .saturating_add((198_000 as Weight).saturating_mul(x as Weight)) // Standard Error: 3000 + .saturating_add((112_000 as Weight).saturating_mul(y as Weight)) + .saturating_add(RocksDbWeight::get().reads(10 as Weight)) + .saturating_add(RocksDbWeight::get().writes(8 as Weight)) + } + fn schedule_leave_delegators() -> Weight { + (30_908_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } + fn execute_leave_delegators(x: u32) -> Weight { + (1_091_000 as Weight) // Standard Error: 14_000 + .saturating_add((37_192_000 as Weight).saturating_mul(x as Weight)) + .saturating_add(RocksDbWeight::get().reads(6 as Weight)) + .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(x as Weight))) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + .saturating_add( + RocksDbWeight::get().writes((2 as Weight).saturating_mul(x as Weight)), + ) + } + fn cancel_leave_delegators() -> Weight { + (26_796_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(5 as Weight)) + .saturating_add(RocksDbWeight::get().writes(3 as Weight)) + } + fn schedule_revoke_delegation() -> Weight { (37_580_000 as Weight) .saturating_add(RocksDbWeight::get().reads(7 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } - fn nominator_bond_more() -> Weight { - (70_867_000 as Weight) + fn delegator_bond_more() -> Weight { + (65_757_000 as Weight) .saturating_add(RocksDbWeight::get().reads(9 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } - fn nominator_bond_less() -> Weight { - (70_857_000 as Weight) + fn schedule_delegator_bond_less() -> Weight { + (70_859_000 as Weight) .saturating_add(RocksDbWeight::get().reads(9 as Weight)) .saturating_add(RocksDbWeight::get().writes(7 as Weight)) } - // If this takes up too much block space, run again on code - // - #743 benchmarks post reward payout optimization were 3x lower per collator, - // 15x lower per nominator - fn active_on_initialize(x: u32, y: u32) -> Weight { - (0 as Weight) - // Standard Error: 299_000 - .saturating_add((208_550_000 as Weight).saturating_mul(x as Weight)) - // Standard Error: 27_000 - .saturating_add((15_580_000 as Weight).saturating_mul(y as Weight)) - .saturating_add(RocksDbWeight::get().reads(26 as Weight)) + fn execute_revoke_delegation() -> Weight { + (87_836_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(10 as Weight)) + .saturating_add(RocksDbWeight::get().writes(7 as Weight)) + } + fn execute_delegator_bond_less() -> Weight { + (80_983_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(11 as Weight)) + .saturating_add(RocksDbWeight::get().writes(8 as Weight)) + } + fn cancel_revoke_delegation() -> Weight { + (37_923_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(7 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + fn cancel_delegator_bond_less() -> Weight { + (70_813_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(7 as Weight)) + .saturating_add(RocksDbWeight::get().writes(4 as Weight)) + } + fn round_transition_on_initialize(x: u32, y: u32) -> Weight { + (0 as Weight) // Standard Error: 4_087_000 + // Standard Error: 12_000 + .saturating_add((100_164_000 as Weight).saturating_mul(x as Weight)) + .saturating_add((1_202_000 as Weight).saturating_mul(y as Weight)) .saturating_add(RocksDbWeight::get().reads((4 as Weight).saturating_mul(x as Weight))) - .saturating_add(RocksDbWeight::get().writes(16 as Weight)) .saturating_add( - RocksDbWeight::get().writes((4 as Weight).saturating_mul(x as Weight)), + RocksDbWeight::get().writes((3 as Weight).saturating_mul(x as Weight)), ) } - fn passive_on_initialize() -> Weight { + fn base_on_initialize() -> Weight { (4_913_000 as Weight).saturating_add(RocksDbWeight::get().reads(1 as Weight)) } + fn pay_one_collator_reward(y: u32) -> Weight { + (0 as Weight) + // Standard Error: 6_000 + .saturating_add((23_284_000 as Weight).saturating_mul(y as Weight)) + .saturating_add(RocksDbWeight::get().reads(11 as Weight)) + .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(y as Weight))) + .saturating_add(RocksDbWeight::get().writes(6 as Weight)) + .saturating_add( + RocksDbWeight::get().writes((1 as Weight).saturating_mul(y as Weight)), + ) + } } diff --git a/pallets/sp-mvm/Cargo.toml b/pallets/sp-mvm/Cargo.toml index 11a8f4aa..4a3069bc 100644 --- a/pallets/sp-mvm/Cargo.toml +++ b/pallets/sp-mvm/Cargo.toml @@ -45,22 +45,22 @@ serde = { version = "1.0", optional = true } once_cell = { default-features = false, version = "1.5.2" } # substrate: scale-info = { version = "1.0", default-features = false, features = ["derive"] } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -timestamp = { default-features = false, package = "pallet-timestamp", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -balances = { default-features = false, package = "pallet-balances", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +timestamp = { default-features = false, package = "pallet-timestamp", git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +balances = { default-features = false, package = "pallet-balances", git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } # logging, `sp_runtime::print`: -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } groupsign = { path = "../groupsign", default-features = false } -sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +sp-io = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } getrandom = { version = "0.2.3", optional = true } # Orml -orml-traits = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } +orml-traits = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } # serde is for lcs/bcs only # used for benchmarking (runtime, std, no-std) @@ -76,13 +76,13 @@ optional = true [dev-dependencies] # serde is for lcs/bcs and construct_runtime # used for tests (std) only -pallet-vesting = { default-features = false, package = "pallet-vesting", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +pallet-vesting = { default-features = false, package = "pallet-vesting", git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } primitives = { path = "../../primitives" } assets = { path = "../../assets" } constants = { path = "../../constants" } module-currencies = { path = "../currencies" } -orml-tokens = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } -orml-currencies = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } +orml-tokens = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } +orml-currencies = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } serde = { package = "serde", version = "1.0.119" } bcs = { package = "bcs", version = "0.1" } env_logger = "0.9.0" diff --git a/pallets/sp-mvm/rpc/Cargo.toml b/pallets/sp-mvm/rpc/Cargo.toml index c7614cf6..3ed78d55 100644 --- a/pallets/sp-mvm/rpc/Cargo.toml +++ b/pallets/sp-mvm/rpc/Cargo.toml @@ -13,13 +13,13 @@ targets = ["x86_64-unknown-linux-gnu"] jsonrpc-core = "18.0" jsonrpc-core-client = "18.0" jsonrpc-derive = "18.0" -sp-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-runtime = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +sp-rpc = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-api = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +frame-support = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-blockchain = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } sp-mvm-rpc-runtime = { version = "0.2.2", path = "./runtime" } -codec = { package = "parity-scale-codec", version = "2.3.0" } +codec = { package = "parity-scale-codec", version = "2.3.1" } serde = { version = "1.0.119", features = [ "derive" ] } # / 1.0.101 fc-rpc-core = { version = "1.0.0" } diff --git a/pallets/sp-mvm/rpc/runtime/Cargo.toml b/pallets/sp-mvm/rpc/runtime/Cargo.toml index ad657eca..5f3c18d7 100644 --- a/pallets/sp-mvm/rpc/runtime/Cargo.toml +++ b/pallets/sp-mvm/rpc/runtime/Cargo.toml @@ -10,13 +10,12 @@ version = "0.2.2" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -sp-std = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-api = { default-features = false, version = '4.0.0-dev', git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -frame-support = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-api = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } sp-mvm = { default-features = false, path = "../../" } -sp-runtime = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -# TODO: update parity-scale-codec to 2.2.0 -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false } +sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +codec = { package = "parity-scale-codec", version = "2.3.1", default-features = false } [features] default = ["std"] diff --git a/pallets/sp-mvm/src/balance.rs b/pallets/sp-mvm/src/balance.rs index 348f284d..d017f873 100644 --- a/pallets/sp-mvm/src/balance.rs +++ b/pallets/sp-mvm/src/balance.rs @@ -11,7 +11,6 @@ //! * get_balance - get current balance of account. //! * add - add tokens to account. //! * sub - reduce account balance on amount. - use core::convert::TryFrom; use core::convert::TryInto; use move_vm::io::traits::{Balance as VmBalance, BalanceAccess}; @@ -47,7 +46,7 @@ pub struct BalancesAdapter { _phantom: core::marker::PhantomData<(AccountId, Currencies, CurrencyId)>, } -impl +impl BalancesAdapter { /// Create new instance of Balance Adapter. @@ -74,7 +73,7 @@ impl /// It's a trait required to Move VM and allows for poxy balances between Substrate and VM. /// Using deposit/withdraw to PalletId we are solving total issuance issue. impl< - AccountId: Encode + Decode + Default, + AccountId: Encode + Decode, Currencies: MultiCurrency + fungibles::Inspect, CurrencyId: FullCodec @@ -247,7 +246,7 @@ pub mod boxed { } impl< - AccountId: Encode + Decode + Sized + Default + 'static, + AccountId: Encode + Decode + Sized + 'static, Currencies: MultiCurrency + fungibles::Inspect + 'static, @@ -286,7 +285,7 @@ pub mod boxed { } impl< - AccountId: Encode + Decode + Sized + Default + 'static, + AccountId: Encode + Decode + Sized + 'static, Currencies: orml_traits::MultiCurrency + fungibles::Inspect + 'static, diff --git a/pallets/sp-mvm/src/lib.rs b/pallets/sp-mvm/src/lib.rs index c1bb351b..70aa9693 100644 --- a/pallets/sp-mvm/src/lib.rs +++ b/pallets/sp-mvm/src/lib.rs @@ -136,6 +136,7 @@ pub mod pallet { #[pallet::pallet] #[pallet::generate_store(pub trait Store)] + #[pallet::without_storage_info] pub struct Pallet(_); // The pallet's runtime storage items. diff --git a/pallets/sp-mvm/tests/common/mock.rs b/pallets/sp-mvm/tests/common/mock.rs index ad01d64a..730b7811 100644 --- a/pallets/sp-mvm/tests/common/mock.rs +++ b/pallets/sp-mvm/tests/common/mock.rs @@ -9,7 +9,7 @@ use parity_scale_codec::{Decode, Encode}; use system::EnsureRoot; use frame_support::{ PalletId, parameter_types, - traits::Everything, + traits::{Everything, ConstU32}, weights::{Weight, constants::WEIGHT_PER_SECOND}, }; use sp_std::vec; @@ -38,7 +38,7 @@ pub const MILLIUNIT: Balance = 1_000_000_000; pub const MICROUNIT: Balance = 1_000_000; // Implement signature just for test. -#[derive(Eq, PartialEq, Clone, Default, Encode, Decode, TypeInfo, Debug)] +#[derive(Eq, PartialEq, Clone, Encode, Decode, TypeInfo, Debug)] pub struct AnySignature(sr25519::Signature); impl Verify for AnySignature { @@ -108,6 +108,7 @@ impl system::Config for Test { type SystemWeightInfo = (); type SS58Prefix = SS58Prefix; type OnSetCode = (); + type MaxConsumers = ConstU32<12>; } // --- gas --- // diff --git a/pallets/sp-mvm/tests/modules.rs b/pallets/sp-mvm/tests/modules.rs new file mode 100644 index 00000000..637101ef --- /dev/null +++ b/pallets/sp-mvm/tests/modules.rs @@ -0,0 +1,63 @@ +/// Tests related to modules/packages publishing. +use frame_support::assert_err_ignore_postinfo; +use frame_support::dispatch::DispatchError; + +mod common; +use common::assets::{modules, ROOT_PACKAGE, USER_PACKAGE}; +use common::mock::*; +use common::addr::*; +use common::utils; + +#[test] +// Publish module as user. +fn publish_module() { + RuntimeBuilder::new().build().execute_with(|| { + let origin = bob_public_key(); + utils::publish_module(origin, &modules::user::STORE, None).unwrap(); + }); +} + +#[test] +/// Check publishing module compiled by one user but published by another one. +fn publish_module_as_wrong_user() { + RuntimeBuilder::new().build().execute_with(|| { + let origin = bob_public_key(); + assert_err_ignore_postinfo!( + utils::publish_module(origin, &modules::root::EVENT_PROXY, None), + DispatchError::Module { + index: 6, + error: 89, + message: Some("ModuleAddressDoesNotMatchSender") + } + ); + }); +} + +#[test] +/// Publish module as root (should be placed under CORE_CODE_ADDRESS). +fn publish_module_as_root() { + RuntimeBuilder::new().build().execute_with(|| { + utils::publish_module_as_root(&modules::root::EVENT_PROXY, None).unwrap(); + }); +} + +#[test] +/// Publish package as user. +fn publish_package_as_user() { + RuntimeBuilder::new().build().execute_with(|| { + let package = &USER_PACKAGE; + let origin = bob_public_key(); + + utils::publish_package(origin, package, None).unwrap(); + }); +} + +#[test] +/// Publish package as root (should be placed under CORE_CODE_ADDRESS). +fn publish_package_as_root() { + RuntimeBuilder::new().build().execute_with(|| { + let package = &ROOT_PACKAGE; + + utils::publish_package_as_root(package, None).unwrap(); + }); +} diff --git a/pallets/sp-mvm/tests/scripts.rs b/pallets/sp-mvm/tests/scripts.rs new file mode 100644 index 00000000..4afba67c --- /dev/null +++ b/pallets/sp-mvm/tests/scripts.rs @@ -0,0 +1,194 @@ +/// Tests related to scripts execution. +use serde::Deserialize; +use move_core_types::identifier::Identifier; +use move_core_types::language_storage::{StructTag, TypeTag}; +use frame_support::assert_err_ignore_postinfo; +use frame_support::dispatch::DispatchError; +use sp_mvm::Event; + +mod common; +use common::assets::{modules, transactions}; +use common::mock::*; +use common::addr::*; +use common::utils; + +/// Check stored value (u64) inside storage. +fn check_stored_value(expected: u64) { + #[derive(Deserialize, Debug, PartialEq)] + struct StoreU64 { + pub val: u64, + } + + let expected = StoreU64 { val: expected }; + + let tag = StructTag { + address: origin_move_addr(), + module: Identifier::new(modules::user::STORE.name()).unwrap(), + name: Identifier::new("U64").unwrap(), + type_params: vec![], + }; + + utils::check_storage_res(origin_move_addr(), tag, expected); +} + +/// Panics with inner message of the passed error. +/// If message does not exist, just panics with debug render of entire error. +fn unwrap_move_err_in_dispatch_err(err: &sp_runtime::DispatchError) -> ! { + match err { + sp_runtime::DispatchError::Module { + message: Some(message), + .. + } => panic!("{}", message), + _ => panic!("{:?}", err), + } +} + +#[test] +/// Execute script and store U64 number inside storage. +fn execute_script() { + RuntimeBuilder::new().build().execute_with(|| { + const EXPECTED: u64 = 42; + let origin = bob_public_key(); + + utils::publish_module(origin, &modules::user::STORE, None).unwrap(); + utils::execute_tx(origin, &transactions::STORE_U64, None).unwrap(); + + check_stored_value(EXPECTED); + }); +} + +#[test] +/// Execute storing of block height inside module by calling script. +fn execute_store_block() { + RuntimeBuilder::new().build().execute_with(|| { + let origin = bob_public_key(); + + utils::publish_module(origin, &modules::user::STORE, None).unwrap(); + + const EXPECTED: u64 = 3; + for _ in 0..EXPECTED { + roll_next_block(); + } + utils::execute_tx(origin, &transactions::STORE_SYSTEM_BLOCK, None).unwrap(); + check_stored_value(EXPECTED); + }); +} + +#[test] +/// Execute storing of timestamp inside module by calling script. +fn execute_store_time() { + RuntimeBuilder::new().build().execute_with(|| { + let origin = bob_public_key(); + + utils::publish_module(origin, &modules::user::STORE, None).unwrap(); + + const EXPECTED: u64 = 3; + for _ in 0..EXPECTED { + roll_next_block(); + } + utils::execute_tx(origin, &transactions::STORE_SYSTEM_TIMESTAMP, None).unwrap(); + check_stored_value(EXPECTED * TIME_BLOCK_MULTIPLIER); + }); +} + +#[test] +/// Check the pallet doesn't allow scripts contains root signers. +fn execute_script_as_root() { + RuntimeBuilder::new().build().execute_with(|| { + let origin = bob_public_key(); + let result = utils::execute_tx(origin, &transactions::AS_ROOT, None); + + assert_err_ignore_postinfo!( + result, + DispatchError::Module { + index: 6, + error: 7, + message: Some("TransactionIsNotAllowedError") + } + ); + }); +} + +#[test] +/// Deploy user module, execute script (storing value in module), check event. +fn execute_script_with_event() { + RuntimeBuilder::new().build().execute_with(|| { + let origin = bob_public_key(); + + utils::publish_module(origin, &modules::user::EVENT_PROXY, None).unwrap(); + + // we need next block because events are not populated on genesis: + roll_next_block(); + + assert!(Sys::events().is_empty()); + + utils::execute_tx(origin, &transactions::EMIT_EVENT, None).unwrap(); + + // construct event: that should be emitted in the method call directly above + let tt = TypeTag::Struct(StructTag { + address: to_move_addr(origin), + module: Identifier::new(modules::user::EVENT_PROXY.name()).unwrap(), + name: Identifier::new("U64").unwrap(), + type_params: Vec::with_capacity(0), + }) + .to_string(); + let tt = tt.as_bytes(); + + // guid is sequence number (8 bytes) followed by account address + let mut guid = vec![0; 8]; + guid.extend(&origin.0); + + let expected = Event::Event(guid, tt.to_vec(), 42u64.to_le_bytes().to_vec()).into(); + + // iterate through array of `EventRecord`s + assert!(Sys::events().iter().any(|rec| { rec.event == expected })) + }); +} + +#[test] +/// Test execution of transaction which __does not__ requires a root/sudo. +/// The Call signied by __ordinar signer__. +fn execute_with_one_signer() { + RuntimeBuilder::new().build().execute_with(|| { + let origin = bob_public_key(); + utils::execute_tx(origin, &transactions::ONE_SIGNER_USER, None) + .expect("tx without root requirement called by ordinar signer"); + }); +} + +#[test] +/// Test execution of transaction which __requires__ a root/sudo signature. +/// The Call signied by __sudo__. +fn execute_with_one_signer_with_root_by_root() { + RuntimeBuilder::new().build().execute_with(|| { + utils::execute_tx_by_root(&transactions::ONE_SIGNER_ROOT, None) + .expect("tx with root requirement called by root origin"); + }); +} + +#[test] +#[should_panic(expected = "TransactionIsNotAllowedError")] +/// Test execution of transaction which __does not__ requires a root/sudo. +/// The Call signied by __sudo__. +fn execute_with_one_signer_by_root() { + RuntimeBuilder::new().build().execute_with(|| { + let error = utils::execute_tx_by_root(&transactions::ONE_SIGNER_USER, None) + .expect_err("tx without root requirement called by root signer should fail") + .error; + unwrap_move_err_in_dispatch_err(&error); + }); +} + +#[test] +#[should_panic(expected = "TransactionIsNotAllowedError")] +/// Test execution of transaction which __requires__ a root/sudo signature. +/// The Call signied by __ordinar signer__, not sudo/root. +fn execute_with_one_signer_with_root() { + RuntimeBuilder::new().build().execute_with(|| { + let origin = bob_public_key(); + let error = utils::execute_tx(origin, &transactions::ONE_SIGNER_ROOT, None) + .expect_err("tx with root requirement called by signed origin should fail") + .error; + unwrap_move_err_in_dispatch_err(&error); + }); +} diff --git a/pallets/transaction-pause/Cargo.toml b/pallets/transaction-pause/Cargo.toml index 42cc1437..89c1bb23 100644 --- a/pallets/transaction-pause/Cargo.toml +++ b/pallets/transaction-pause/Cargo.toml @@ -9,32 +9,28 @@ edition = "2021" serde = { version = "1.0", optional = true } codec = { package = "parity-scale-codec", version = "2.3.1", default-features = false } scale-info = { version = "1.0", default-features = false, features = ["derive"] } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false, optional = true } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false, optional = true } +frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } primitives = { default-features = false, path = "../../primitives" } # Orml dependencies -orml-traits = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } -orml-utilities = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } - +orml-traits = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } +orml-utilities = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } [dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13"} -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13"} -pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } -orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } -orml-utilities = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } -orml-tokens = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } - - -primitives = { path = "../../primitives" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16"} +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16"} +pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } +orml-traits = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } +orml-utilities = { git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } +orml-tokens = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } [features] default = ["std"] @@ -46,4 +42,10 @@ std = [ "sp-runtime/std", "sp-std/std", "scale-info/std", + "primitives/std", + "orml-traits/std", + "orml-utilities/std", + "sp-io/std", + "sp-core/std", + "codec/std", ] diff --git a/pallets/transaction-pause/src/lib.rs b/pallets/transaction-pause/src/lib.rs index 227d52ba..7ef410f1 100644 --- a/pallets/transaction-pause/src/lib.rs +++ b/pallets/transaction-pause/src/lib.rs @@ -57,6 +57,7 @@ pub mod module { StorageMap<_, Twox64Concat, (Vec, Vec), (), OptionQuery>; #[pallet::pallet] + #[pallet::without_storage_info] pub struct Pallet(_); #[pallet::hooks] diff --git a/pallets/transaction-pause/src/mock.rs b/pallets/transaction-pause/src/mock.rs index cb9c5bfc..728e0568 100644 --- a/pallets/transaction-pause/src/mock.rs +++ b/pallets/transaction-pause/src/mock.rs @@ -3,7 +3,7 @@ use super::*; use frame_support::{ construct_runtime, ord_parameter_types, parameter_types, - traits::{Everything, Nothing}, + traits::{Everything, Nothing, ConstU32}, }; use frame_system::{EnsureSignedBy}; use orml_traits::parameter_type_with_key; @@ -47,6 +47,7 @@ impl frame_system::Config for Runtime { type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); + type MaxConsumers = ConstU32<12>; } parameter_types! { diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 0e55f1d8..0e4fe551 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -11,9 +11,9 @@ version = '3.0.0' serde = { version = "1.0", optional = true } codec = { package = "parity-scale-codec", version = "2.3.1", default-features = false, features = ["max-encoded-len"] } scale-info = { version = "1.0", default-features = false, features = ["derive"] } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } [features] default = ["std"] diff --git a/primitives/src/currency.rs b/primitives/src/currency.rs index 34bde0dd..fc3f524c 100644 --- a/primitives/src/currency.rs +++ b/primitives/src/currency.rs @@ -4,7 +4,7 @@ use sp_std::convert::TryFrom; use sp_std::vec::Vec; use sp_std::cmp::PartialEq; use sp_std::default::Default; -use codec::{Decode, Encode}; +use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; #[cfg(feature = "std")] @@ -157,7 +157,7 @@ pub const NATIVE_SYM: &'static [u8] = { #[cfg(not(feature = "pont"))] def_currencies! { /// Currencies id. - #[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, PartialOrd, Ord, TypeInfo)] + #[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, PartialOrd, Ord, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum CurrencyId { /// Our native currency. diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 38eefa8c..0fc82e8f 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -11,7 +11,7 @@ version = '3.0.0' targets = ['x86_64-unknown-linux-gnu'] [build-dependencies] -substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } +substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } [dependencies.codec] default-features = false @@ -26,64 +26,64 @@ smallvec = "1.6" # Substrate dependencies scale-info = { version = "1.0", default-features = false, features = ["derive"] } -frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -frame-executive = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -frame-system-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -frame-system-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-sudo = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-transaction-payment = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-vesting = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-treasury = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-democracy = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-scheduler = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } +frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +frame-executive = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +frame-system-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +frame-system-rpc-runtime-api = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-balances = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-randomness-collective-flip = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-sudo = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-timestamp = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-transaction-payment = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-transaction-payment-rpc-runtime-api = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-vesting = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-treasury = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-democracy = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-scheduler = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } # Substrate Primitives dependencies -sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-block-builder = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-inherents = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-offchain = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-session = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-transaction-pool = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -sp-version = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-multisig = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot.git", branch = "release-v0.9.13" } -xcm = { default-features = false, git = "https://github.com/paritytech/polkadot.git", branch = "release-v0.9.13" } -xcm-builder = { default-features = false, git = "https://github.com/paritytech/polkadot.git", branch = "release-v0.9.13" } -xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot.git", branch = "release-v0.9.13" } -polkadot-parachain = { default-features = false, git = "https://github.com/paritytech/polkadot.git", branch = "release-v0.9.13" } -polkadot-primitives = { default-features = false, git = "https://github.com/paritytech/polkadot.git", branch = "release-v0.9.13" } +sp-api = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-block-builder = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-inherents = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-offchain = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-session = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-transaction-pool = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +sp-version = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-multisig = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +pallet-xcm = { default-features = false, git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.16' } +xcm = { default-features = false, git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.16' } +xcm-builder = { default-features = false, git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.16' } +xcm-executor = { default-features = false, git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.16' } +polkadot-parachain = { default-features = false, git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.16' } +polkadot-primitives = { default-features = false, git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.16' } # Nimbus dependencies -nimbus-primitives = { default-features = false, git = "https://github.com/pontem-network/nimbus.git", branch = "polkadot-v0.9.13" } -pallet-author-inherent = { default-features = false, git = "https://github.com/pontem-network/nimbus.git", branch = "polkadot-v0.9.13" } -pallet-author-slot-filter = { default-features = false, git = "https://github.com/pontem-network/nimbus.git", branch = "polkadot-v0.9.13" } +nimbus-primitives = { default-features = false, git = "https://github.com/pontem-network/nimbus", branch = 'polkadot-v0.9.16' } +pallet-author-inherent = { default-features = false, git = 'https://github.com/pontem-network/nimbus', branch = 'polkadot-v0.9.16' } +pallet-author-slot-filter = { default-features = false, git = "https://github.com/pontem-network/nimbus", branch = 'polkadot-v0.9.16' } # Cumulus Dependencies -parachain-info = { default-features = false, git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-pallet-parachain-system = { default-features = false, git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-pallet-xcm = { default-features = false, git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-pallet-xcmp-queue = { default-features = false, git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-pallet-dmp-queue = { default-features = false, git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-primitives-utility = { default-features = false, git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-primitives-core = { default-features = false, git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } -cumulus-primitives-timestamp = { default-features = false, git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.13" } +parachain-info = { default-features = false, git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-pallet-parachain-system = { default-features = false, git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-pallet-xcm = { default-features = false, git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-pallet-xcmp-queue = { default-features = false, git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-pallet-dmp-queue = { default-features = false, git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-primitives-utility = { default-features = false, git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-primitives-core = { default-features = false, git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } +cumulus-primitives-timestamp = { default-features = false, git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.16' } # xtokens -orml-xtokens = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } -orml-tokens = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } -orml-xcm = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } -orml-traits = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } -orml-xcm-support = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } -orml-unknown-tokens = { default-features = false, git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "88f1b4b1ac6ea0621d188dfa7e64fd2915dd81d5" } +orml-xtokens = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } +orml-tokens = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } +orml-xcm = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } +orml-traits = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } +orml-xcm-support = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } +orml-unknown-tokens = { default-features = false, git = 'https://github.com/open-web3-stack/open-runtime-module-library', rev = '213f743af2d6d2c94f235613d7e7ff21b093297c' } # local dependencies sp-mvm = { path = "../pallets/sp-mvm", default-features = false } @@ -97,11 +97,11 @@ groupsign = { path = "../pallets/groupsign", default-features = false } transaction-pause = { path = "../pallets/transaction-pause", default-features = false } [dev-dependencies] -xcm-emulator = { git = "https://github.com/pontem-network/xcm-simulator", branch = "polkadot-v0.9.13" } -polkadot-runtime-parachains = { default-features = false, git = "https://github.com/paritytech/polkadot.git", branch = "release-v0.9.13" } -kusama-runtime = { git = "https://github.com/paritytech/polkadot.git", branch = "release-v0.9.13" } -sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.13" } -assets = { path = "../assets", default-features = false } +xcm-emulator = { git = 'https://github.com/pontem-network/xcm-simulator', branch = 'polkadot-v0.9.16' } +polkadot-runtime-parachains = { default-features = false, git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.16' } +kusama-runtime = { git = 'https://github.com/paritytech/polkadot.git', branch = 'release-v0.9.16' } +sp-io = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.16' } +assets = { path = '../assets', default-features = false } env_logger = "0.9.0" test-log = "0.2.8" diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index bdafbd5c..d2ae874f 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -51,7 +51,7 @@ pub use frame_support::{ construct_runtime, parameter_types, StorageValue, match_type, traits::{ KeyOwnerProofSystem, Randomness, IsInVec, Everything, Nothing, EnsureOrigin, - OnUnbalanced, Imbalance, Get, Contains, EqualPrivilegeOnly, + OnUnbalanced, Imbalance, Get, Contains, EqualPrivilegeOnly, ConstU32, }, weights::{ Weight, IdentityFee, DispatchClass, @@ -107,6 +107,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, + state_version: 0, }; /// 1 in 4 blocks (on average) will be primary babe blocks @@ -131,7 +132,7 @@ const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(65); parameter_types! { pub const Version: RuntimeVersion = VERSION; pub const BlockHashCount: BlockNumber = 2400; - /// We allow for 2 seconds of compute with a 6 second average block time. + /// We allow for 2 seconds of compute with a 12 second average block time. pub RuntimeBlockWeights: BlockWeights = BlockWeights::builder() .base_block(BlockExecutionWeight::get()) .for_class(DispatchClass::all(), |weights| { @@ -206,6 +207,7 @@ impl frame_system::Config for Runtime { /// What to do if the user wants the code set to something. Just use `()` unless you are in /// cumulus. type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; + type MaxConsumers = ConstU32<12>; } parameter_types! { @@ -228,13 +230,20 @@ parameter_types! { // Allow emergency. pub const InstantAllowed: bool = true; } + pub struct AssumeRootIsSudo(); impl EnsureOrigin for AssumeRootIsSudo { type Success = AccountId; + fn try_origin(o: Origin) -> Result { + use sp_core::Decode; + let f: Result<_, _> = o.into(); f.and_then(|t| match t { - RawOrigin::Root => Ok(Sudo::key()), + RawOrigin::Root => Ok(Sudo::key().unwrap_or( + AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()) + .expect("infinite length input; no invalid inputs for type; qed"), + )), r => Err(Origin::from(r)), }) } @@ -288,6 +297,7 @@ parameter_types! { /// This value would be slashed if proposal rejected. pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = CurrencyId::NATIVE.times(100); + pub const ProposalBondMaximum: Balance = CurrencyId::NATIVE.times(1000); pub const MaxApprovals: u32 = 100; } @@ -304,6 +314,7 @@ impl pallet_treasury::Config for Runtime { type OnSlash = Treasury; type ProposalBond = ProposalBond; type ProposalBondMinimum = ProposalBondMinimum; + type ProposalBondMaximum = ProposalBondMaximum; type SpendPeriod = SpendPeriod; // Not burning. type Burn = (); @@ -315,6 +326,7 @@ impl pallet_treasury::Config for Runtime { parameter_types! { pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * RuntimeBlockWeights::get().max_block; pub const MaxScheduledPerBlock: u32 = 50; + pub const NoPreimagePostponement: Option = None; } impl pallet_scheduler::Config for Runtime { @@ -327,6 +339,8 @@ impl pallet_scheduler::Config for Runtime { type OriginPrivilegeCmp = EqualPrivilegeOnly; type MaxScheduledPerBlock = MaxScheduledPerBlock; type WeightInfo = pallet_scheduler::weights::SubstrateWeight; + type PreimageProvider = (); + type NoPreimagePostponement = NoPreimagePostponement; } parameter_types! { @@ -426,7 +440,7 @@ parameter_types! { impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; - type OnValidationData = (); + type OnSystemEvent = (); type SelfParaId = parachain_info::Pallet; type OutboundXcmpMessageSource = XcmpQueue; type XcmpMessageHandler = XcmpQueue; @@ -444,18 +458,24 @@ parameter_types! { pub const DefaultBlocksPerRound: u32 = 300; /// Collator candidate exits are delayed by 2 hours (2 * 300 * block_time) pub const LeaveCandidatesDelay: u32 = 2; + // Rounds before the candidate bond increase/decrease can be executed. + pub const CandidateBondLessDelay: u32 = 2; /// Nominator exits are delayed by 2 hours (2 * 300 * block_time) - pub const LeaveNominatorsDelay: u32 = 2; + pub const LeaveDelegatorsDelay: u32 = 2; /// Nomination revocations are delayed by 2 hours (2 * 300 * block_time) - pub const RevokeNominationDelay: u32 = 2; + pub const RevokeDelegationDelay: u32 = 2; + /// Rounds before the delegator bond increase/decrease can be executed + pub const DelegationBondLessDelay: u32 = 2; /// Reward payments are delayed by 2 hours (2 * 300 * block_time) pub const RewardPaymentDelay: u32 = 2; /// Minimum 8 collators selected per round, default at genesis and minimum forever after pub const MinSelectedCandidates: u32 = 8; - /// Maximum 10 nominators per collator - pub const MaxNominatorsPerCollator: u32 = 10; - /// Maximum 25 collators per nominator - pub const MaxCollatorsPerNominator: u32 = 25; + /// Maximum top 10 delegators per collator metters + pub const MaxTopDelegationsPerCandidate: u32 = 10; + /// Maximum bottom delegations per candidate + pub const MaxBottomDelegationsPerCandidate: u32 = 50; + /// Maximum delegations per delegator + pub const MaxDelegationsPerDelegator: u32 = 25; /// Default fixed percent a collator takes off the top of due rewards is 20% pub const DefaultCollatorCommission: Perbill = Perbill::from_percent(20); /// Default percent of inflation set aside for parachain bond every round @@ -463,9 +483,9 @@ parameter_types! { /// Minimum stake required to become a collator is 1_000 pub const MinCollatorStk: Balance = CurrencyId::NATIVE.times(1000); /// Minimum stake required to be reserved to be a candidate is 100 - pub const MinCollatorCandidateStk: Balance = CurrencyId::NATIVE.times(100); - /// Minimum stake required to be reserved to be a nominator is 5 - pub const MinNominatorStk: Balance = CurrencyId::NATIVE.times(1); + pub const MinCandidateStk: Balance = CurrencyId::NATIVE.times(100); + /// Minimum stake required to be reserved to be a delegator is 1. + pub const MinDelegatorStk: Balance = CurrencyId::NATIVE.times(1); } impl parachain_staking::Config for Runtime { type Event = Event; @@ -473,25 +493,27 @@ impl parachain_staking::Config for Runtime { type MonetaryGovernanceOrigin = EnsureRoot; type MinBlocksPerRound = MinBlocksPerRound; type DefaultBlocksPerRound = DefaultBlocksPerRound; + type CandidateBondLessDelay = CandidateBondLessDelay; type LeaveCandidatesDelay = LeaveCandidatesDelay; - type LeaveNominatorsDelay = LeaveNominatorsDelay; - type RevokeNominationDelay = RevokeNominationDelay; + type LeaveDelegatorsDelay = LeaveDelegatorsDelay; + type RevokeDelegationDelay = RevokeDelegationDelay; + type DelegationBondLessDelay = DelegationBondLessDelay; type RewardPaymentDelay = RewardPaymentDelay; type MinSelectedCandidates = MinSelectedCandidates; - type MaxNominatorsPerCollator = MaxNominatorsPerCollator; - type MaxCollatorsPerNominator = MaxCollatorsPerNominator; + type MaxTopDelegationsPerCandidate = MaxTopDelegationsPerCandidate; + type MaxBottomDelegationsPerCandidate = MaxBottomDelegationsPerCandidate; + type MaxDelegationsPerDelegator = MaxDelegationsPerDelegator; type DefaultCollatorCommission = DefaultCollatorCommission; type DefaultParachainBondReservePercent = DefaultParachainBondReservePercent; type MinCollatorStk = MinCollatorStk; - type MinCollatorCandidateStk = MinCollatorCandidateStk; - type MinNomination = MinNominatorStk; - type MinNominatorStk = MinNominatorStk; + type MinCandidateStk = MinCandidateStk; + type MinDelegatorStk = MinDelegatorStk; + type MinDelegation = MinDelegatorStk; type WeightInfo = parachain_staking::weights::SubstrateWeight; } // The pallet connect authors mapping, slots, and implement block executor for nimbus consensus. impl pallet_author_inherent::Config for Runtime { - type AuthorId = NimbusId; type SlotBeacon = RelaychainBlockNumberProvider; type AccountLookup = AuthorMapping; type EventHandler = ParachainStaking; @@ -506,7 +528,6 @@ parameter_types! { // We need author mapping to connect Nimbus Ids with Account Ids, all collators should register his AuthorId. impl pallet_author_mapping::Config for Runtime { type Event = Event; - type AuthorId = NimbusId; type DepositCurrency = Balances; type DepositAmount = DepositAmount; type WeightInfo = pallet_author_mapping::weights::SubstrateWeight; @@ -548,6 +569,7 @@ pub type LocalAssetTransactor = MultiCurrencyAdapter< LocationToAccountId, CurrencyId, CurrencyIdConvert, + (), >; /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, @@ -746,6 +768,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; + type ExecuteOverweightOrigin = EnsureRoot; } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -891,6 +914,11 @@ impl Convert> for CurrencyIdConvert { parents: 1, interior: X2(Parachain(_id), GeneralKey(key)), } if key.to_vec() == CurrencyId::NATIVE.symbol() => Some(CurrencyId::NATIVE), + // adapt for reanchor canonical location: https://github.com/paritytech/polkadot/pull/4470 + MultiLocation { + parents: 0, + interior: X1(GeneralKey(key)), + } if key.to_vec() == CurrencyId::NATIVE.symbol() => Some(CurrencyId::NATIVE), _ => None, } } @@ -964,6 +992,7 @@ impl Convert for AccountIdToMultiLocation { parameter_types! { pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into()))); pub const BaseXcmWeight: Weight = 100_000_000; + pub const MaxAssetsForTransfer: usize = 2; } impl orml_xtokens::Config for Runtime { @@ -977,6 +1006,7 @@ impl orml_xtokens::Config for Runtime { type Weigher = FixedWeightBounds; type BaseXcmWeight = BaseXcmWeight; type LocationInverter = LocationInverter; + type MaxAssetsForTransfer = MaxAssetsForTransfer; } impl orml_xcm::Config for Runtime { @@ -1043,7 +1073,7 @@ construct_runtime!( AuthorMapping: pallet_author_mapping::{Pallet, Call, Config, Storage, Event} = 43, // Democracy - Scheduler: pallet_scheduler::{Pallet, Call, Storage, Config, Event} = 50, + Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event} = 50, Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event} = 51, Democracy: pallet_democracy::{Pallet, Call, Storage, Config, Event} = 52, @@ -1096,7 +1126,7 @@ pub type Executive = frame_executive::Executive< Block, frame_system::ChainContext, Runtime, - AllPallets, + AllPalletsReversedWithSystemFirst, >; impl_runtime_apis! { @@ -1158,8 +1188,8 @@ impl_runtime_apis! { } impl cumulus_primitives_core::CollectCollationInfo for Runtime { - fn collect_collation_info() -> cumulus_primitives_core::CollationInfo { - ParachainSystem::collect_collation_info() + fn collect_collation_info(header: &::Header) -> cumulus_primitives_core::CollationInfo { + ParachainSystem::collect_collation_info(header) } } @@ -1248,28 +1278,56 @@ impl_runtime_apis! { } } - impl nimbus_primitives::AuthorFilterAPI for Runtime { + impl nimbus_primitives::NimbusApi for Runtime { fn can_author( - author: NimbusId, + author: nimbus_primitives::NimbusId, slot: u32, parent_header: &::Header ) -> bool { + use nimbus_primitives::CanAuthor; + let block_number = parent_header.number + 1; + // The Moonbeam runtimes use an entropy source that needs to do some accounting // work during block initialization. Therefore we initialize it here to match // the state it will be in when the next block is being executed. use frame_support::traits::OnInitialize; - use nimbus_primitives::CanAuthor; - System::initialize( - &(parent_header.number + 1), + &block_number, &parent_header.hash(), &parent_header.digest, - frame_system::InitKind::Inspection ); - RandomnessCollectiveFlip::on_initialize(System::block_number()); + RandomnessCollectiveFlip::on_initialize(block_number); + + // Because the staking solution calculates the next staking set at the beginning + // of the first block in the new round, the only way to accurately predict the + // authors is to compute the selection during prediction. + if parachain_staking::Pallet::::round().should_update(block_number) { + // get author account id + use nimbus_primitives::AccountLookup; + let author_account_id = if let Some(account) = + pallet_author_mapping::Pallet::::lookup_account(&author) { + account + } else { + // return false if author mapping not registered like in can_author impl + return false + }; + // predict eligibility post-selection by computing selection results now + let (eligible, _) = + pallet_author_slot_filter::compute_pseudo_random_subset::( + parachain_staking::Pallet::::compute_top_candidates(), + &slot + ); + eligible.contains(&author_account_id) + } else { + AuthorInherent::can_author(&author, &slot) + } + } + } - // And now the actual prediction call - AuthorInherent::can_author(&author, &slot) + // We also implement the old AuthorFilterAPI to meet the trait bounds on the client side. + impl nimbus_primitives::AuthorFilterAPI for Runtime { + fn can_author(_: NimbusId, _: u32, _: &::Header) -> bool { + panic!("AuthorFilterAPI is no longer supported. Please update your client.") } } diff --git a/runtime/src/tests/parachain/mock_runtime.rs b/runtime/src/tests/parachain/mock_runtime.rs index c1840703..46b2d32c 100644 --- a/runtime/src/tests/parachain/mock_runtime.rs +++ b/runtime/src/tests/parachain/mock_runtime.rs @@ -11,7 +11,7 @@ use sp_runtime::{ use serde::{Deserialize, Serialize}; use sp_core::RuntimeDebug; -use codec::{Decode, Encode}; +use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; // Polkadot & XCM imports @@ -43,7 +43,7 @@ pub use frame_support::{ construct_runtime, parameter_types, StorageValue, match_type, traits::{ KeyOwnerProofSystem, Randomness, IsInVec, Everything, Nothing, EnsureOrigin, - OnUnbalanced, Imbalance, Get, + OnUnbalanced, Imbalance, Get, ConstU32, }, weights::{ Weight, IdentityFee, DispatchClass, @@ -76,7 +76,7 @@ pub type BlockNumber = u64; pub type Index = u64; parameter_types! { - pub const BlockHashCount: BlockNumber = 250; + pub const BlockHashCount: BlockNumber = 2400; } impl frame_system::Config for Runtime { @@ -103,10 +103,23 @@ impl frame_system::Config for Runtime { type SS58Prefix = (); type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; type Version = (); + type MaxConsumers = ConstU32<12>; } // Currencies id. -#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, PartialOrd, Ord, TypeInfo)] +#[derive( + Encode, + Decode, + Eq, + PartialEq, + Copy, + Clone, + RuntimeDebug, + PartialOrd, + Ord, + TypeInfo, + MaxEncodedLen, +)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum CurrencyId { // Relaychain's currency. @@ -141,7 +154,7 @@ parameter_types! { impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; - type OnValidationData = (); + type OnSystemEvent = (); type SelfParaId = parachain_info::Pallet; type OutboundXcmpMessageSource = XcmpQueue; type XcmpMessageHandler = XcmpQueue; @@ -179,6 +192,7 @@ pub type LocalAssetTransactor = MultiCurrencyAdapter< LocationToAccountId, CurrencyId, CurrencyIdConvert, + (), >; /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, @@ -381,6 +395,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; + type ExecuteOverweightOrigin = EnsureRoot; } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -522,6 +537,7 @@ impl Convert for AccountIdToMultiLocation { parameter_types! { pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into()))); pub const BaseXcmWeight: Weight = 100_000_000; + pub const MaxAssetsForTransfer: usize = 2; } impl orml_xtokens::Config for Runtime { @@ -535,6 +551,7 @@ impl orml_xtokens::Config for Runtime { type Weigher = FixedWeightBounds; type BaseXcmWeight = BaseXcmWeight; type LocationInverter = LocationInverter; + type MaxAssetsForTransfer = MaxAssetsForTransfer; } impl orml_xcm::Config for Runtime { diff --git a/runtime/src/tests/parachain/mod.rs b/runtime/src/tests/parachain/mod.rs index ad99d833..aa75f9a6 100644 --- a/runtime/src/tests/parachain/mod.rs +++ b/runtime/src/tests/parachain/mod.rs @@ -30,7 +30,7 @@ decl_test_parachain! { decl_test_relay_chain! { pub struct Relay { Runtime = kusama_runtime::Runtime, - XcmConfig = kusama_runtime::XcmConfig, + XcmConfig = kusama_runtime::xcm_config::XcmConfig, new_ext = relay_ext(), } } @@ -124,8 +124,9 @@ pub fn para_ext(parachain_id: u32) -> TestExternalities { fn default_parachains_host_configuration() -> HostConfiguration { HostConfiguration { - validation_upgrade_frequency: 1u32, - validation_upgrade_delay: 1, + minimum_validation_upgrade_delay: 5, + validation_upgrade_cooldown: 10u32, + validation_upgrade_delay: 10, code_retention_period: 1200, max_code_size: MAX_CODE_SIZE, max_pov_size: MAX_POV_SIZE, diff --git a/runtime/src/tests/parachain/parachain.rs b/runtime/src/tests/parachain/parachain.rs index 6de210fb..d73012fd 100644 --- a/runtime/src/tests/parachain/parachain.rs +++ b/runtime/src/tests/parachain/parachain.rs @@ -174,6 +174,7 @@ fn send_relay_chain_asset_to_sibling() { fn send_self_parachain_asset_to_sibling() { TestNet::reset(); + // Send to paracahin B native currency from parachain A. ParaA::execute_with(|| { assert_ok!(ParaAXTokens::transfer( Some(Accounts::ALICE.account()).into(),