diff --git a/Cargo.lock b/Cargo.lock index b79b988ce..d9dc87b26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -200,7 +200,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -607,7 +607,7 @@ checksum = "965c2d33e53cb6b267e148a4cb0760bc01f4904c1cd4bb4002a085bb016d1490" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", "synstructure 0.13.1", ] @@ -630,7 +630,7 @@ checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -688,7 +688,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -738,7 +738,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -825,7 +825,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -1246,7 +1246,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -1645,7 +1645,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -1672,7 +1672,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -1689,7 +1689,7 @@ checksum = "98532a60dedaebc4848cb2cba5023337cc9ea3af16a5b062633fabfd9f18fb60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -1713,7 +1713,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -1724,7 +1724,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -1833,7 +1833,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -1846,7 +1846,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.1", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -1935,7 +1935,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -1959,7 +1959,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.90", + "syn 2.0.87", "termcolor", "toml 0.8.19", "walkdir", @@ -2121,7 +2121,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -2141,7 +2141,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -2334,7 +2334,7 @@ dependencies = [ "prettyplease 0.2.22", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -2640,12 +2640,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foldhash" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" - [[package]] name = "foreign-types" version = "0.3.2" @@ -2975,7 +2969,7 @@ dependencies = [ "proc-macro2", "quote", "sp-crypto-hashing 0.1.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409)", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -2988,7 +2982,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -3000,7 +2994,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -3011,7 +3005,7 @@ checksum = "68672b9ec6fe72d259d3879dc212c5e42e977588cdac830c76f54d9f492aeb58" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -3021,7 +3015,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -3192,7 +3186,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -3481,11 +3475,6 @@ name = "hashbrown" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" -dependencies = [ - "allocator-api2", - "equivalent", - "foldhash", -] [[package]] name = "hashlink" @@ -3709,9 +3698,9 @@ dependencies = [ [[package]] name = "hyper" -version = "1.5.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbbff0a806a4728c99295b254c8838933b5b082d75e3cb70c8dab21fdfbcfa9a" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ "bytes", "futures-channel", @@ -3745,15 +3734,15 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.10" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ "bytes", "futures-util", "http 1.1.0", "http-body 1.0.1", - "hyper 1.5.0", + "hyper 1.4.1", "pin-project-lite", "tokio", "tower-service", @@ -4106,9 +4095,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.24.7" +version = "0.24.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5c71d8c1a731cc4227c2f698d377e7848ca12c8a48866fc5e6951c43a4db843" +checksum = "126b48a5acc3c52fbd5381a77898cb60e145123179588a29e7ac48f9c06e401b" dependencies = [ "jsonrpsee-core", "jsonrpsee-proc-macros", @@ -4120,9 +4109,9 @@ dependencies = [ [[package]] name = "jsonrpsee-core" -version = "0.24.7" +version = "0.24.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2882f6f8acb9fdaec7cefc4fd607119a9bd709831df7d7672a1d3b644628280" +checksum = "b0e503369a76e195b65af35058add0e6900b794a4e9a9316900ddd3a87a80477" dependencies = [ "async-trait", "bytes", @@ -4143,28 +4132,28 @@ dependencies = [ [[package]] name = "jsonrpsee-proc-macros" -version = "0.24.7" +version = "0.24.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06c01ae0007548e73412c08e2285ffe5d723195bf268bce67b1b77c3bb2a14d" +checksum = "fc660a9389e2748e794a40673a4155d501f32db667757cdb80edeff0306b489b" dependencies = [ "heck 0.5.0", "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] name = "jsonrpsee-server" -version = "0.24.7" +version = "0.24.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82ad8ddc14be1d4290cd68046e7d1d37acd408efed6d3ca08aefcc3ad6da069c" +checksum = "af6e6c9b6d975edcb443565d648b605f3e85a04ec63aa6941811a8894cc9cded" dependencies = [ "futures-util", "http 1.1.0", "http-body 1.0.1", "http-body-util", - "hyper 1.5.0", + "hyper 1.4.1", "hyper-util", "jsonrpsee-core", "jsonrpsee-types", @@ -4183,9 +4172,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.24.7" +version = "0.24.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a178c60086f24cc35bb82f57c651d0d25d99c4742b4d335de04e97fa1f08a8a1" +checksum = "d8fb16314327cbc94fdf7965ef7e4422509cd5597f76d137bd104eb34aeede67" dependencies = [ "http 1.1.0", "serde", @@ -4364,7 +4353,7 @@ dependencies = [ "libp2p-identity", "log", "multiaddr 0.18.2", - "multihash 0.19.2", + "multihash 0.19.1", "multistream-select", "once_cell", "parking_lot 0.12.3", @@ -4409,7 +4398,7 @@ dependencies = [ "libp2p-identity", "libp2p-swarm", "log", - "lru 0.12.5", + "lru 0.12.4", "quick-protobuf", "quick-protobuf-codec", "smallvec", @@ -4426,7 +4415,7 @@ dependencies = [ "bs58 0.5.1", "ed25519-dalek", "hkdf", - "multihash 0.19.2", + "multihash 0.19.1", "quick-protobuf", "rand", "sha2 0.10.8", @@ -4515,7 +4504,7 @@ dependencies = [ "libp2p-identity", "log", "multiaddr 0.18.2", - "multihash 0.19.2", + "multihash 0.19.1", "once_cell", "quick-protobuf", "rand", @@ -4620,7 +4609,7 @@ dependencies = [ "proc-macro-warning 0.4.2", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -4958,11 +4947,11 @@ dependencies = [ [[package]] name = "lru" -version = "0.12.5" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" +checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" dependencies = [ - "hashbrown 0.15.0", + "hashbrown 0.14.5", ] [[package]] @@ -5011,7 +5000,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -5025,7 +5014,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -5036,7 +5025,7 @@ checksum = "b02abfe41815b5bd98dbd4260173db2c116dda171dc0fe7838cb206333b83308" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -5047,7 +5036,7 @@ checksum = "73ea28ee64b88876bf45277ed9a5817c1817df061a74f2b988971a12570e5869" dependencies = [ "macro_magic_core", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -5261,7 +5250,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -5294,7 +5283,7 @@ dependencies = [ "data-encoding", "libp2p-identity", "multibase", - "multihash 0.19.2", + "multihash 0.19.1", "percent-encoding", "serde", "static_assertions", @@ -5349,12 +5338,12 @@ dependencies = [ [[package]] name = "multihash" -version = "0.19.2" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc41f430805af9d1cf4adae4ed2149c759b877b01d909a1f40256188d09345d2" +checksum = "076d548d76a0e2a0d4ab471d0b1c36c577786dfc4471242035d97a12a735c492" dependencies = [ "core2", - "unsigned-varint 0.8.0", + "unsigned-varint 0.7.2", ] [[package]] @@ -5377,6 +5366,12 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +[[package]] +name = "multimap" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03" + [[package]] name = "multistream-select" version = "0.13.0" @@ -5415,7 +5410,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -5874,7 +5869,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -5948,9 +5943,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.68" +version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ "bitflags 2.6.0", "cfg-if", @@ -5969,7 +5964,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -5980,18 +5975,18 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "300.4.0+3.4.0" +version = "300.3.2+3.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a709e02f2b4aca747929cca5ed248880847c650233cf8b8cdc48f40aaf4898a6" +checksum = "a211a18d945ef7e648cc6e0058f4c548ee46aab922ea203e0d30e966ea23647b" dependencies = [ "cc", ] [[package]] name = "openssl-sys" -version = "0.9.104" +version = "0.9.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" dependencies = [ "cc", "libc", @@ -6819,7 +6814,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -6860,7 +6855,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -6940,7 +6935,7 @@ dependencies = [ "polkavm-common", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -6950,7 +6945,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -7090,7 +7085,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -7170,7 +7165,7 @@ checksum = "3d1eaa7fa0aa1929ffdf7eeb6eac234dde6268914a14ad44d23521ab6a9b258e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -7181,14 +7176,14 @@ checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] name = "proc-macro2" -version = "1.0.92" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -7209,7 +7204,7 @@ dependencies = [ "quote", "regex", "sp-crypto-hashing 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -7246,7 +7241,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -7280,7 +7275,7 @@ dependencies = [ "itertools 0.10.5", "lazy_static", "log", - "multimap", + "multimap 0.8.3", "petgraph", "prettyplease 0.1.25", "prost 0.11.9", @@ -7301,14 +7296,14 @@ dependencies = [ "heck 0.5.0", "itertools 0.12.1", "log", - "multimap", + "multimap 0.10.0", "once_cell", "petgraph", "prettyplease 0.2.22", "prost 0.12.6", "prost-types 0.12.6", "regex", - "syn 2.0.90", + "syn 2.0.87", "tempfile", ] @@ -7335,7 +7330,7 @@ dependencies = [ "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -7662,7 +7657,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -8132,7 +8127,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -8754,7 +8749,7 @@ dependencies = [ "litep2p", "log", "multiaddr 0.18.2", - "multihash 0.19.2", + "multihash 0.19.1", "rand", "thiserror", "zeroize", @@ -8866,7 +8861,7 @@ dependencies = [ "governor", "http 1.1.0", "http-body-util", - "hyper 1.5.0", + "hyper 1.4.1", "ip_network", "jsonrpsee", "log", @@ -9064,7 +9059,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -9362,9 +9357,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.215" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] @@ -9399,13 +9394,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -9466,7 +9461,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -9726,7 +9721,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -9919,7 +9914,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/paritytech/polkadot-sdk#41a5d8ec5f3d3d0ff82899be66113b223395ade5" +source = "git+https://github.com/paritytech/polkadot-sdk#c1238b64431b4c74d88c082099caed36177b5b11" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -9990,7 +9985,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable dependencies = [ "quote", "sp-crypto-hashing 0.1.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409)", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -10009,23 +10004,23 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#41a5d8ec5f3d3d0ff82899be66113b223395ade5" +source = "git+https://github.com/paritytech/polkadot-sdk#c1238b64431b4c74d88c082099caed36177b5b11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/paritytech/polkadot-sdk#41a5d8ec5f3d3d0ff82899be66113b223395ade5" +source = "git+https://github.com/paritytech/polkadot-sdk#c1238b64431b4c74d88c082099caed36177b5b11" dependencies = [ "environmental", "parity-scale-codec", @@ -10203,7 +10198,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#41a5d8ec5f3d3d0ff82899be66113b223395ade5" +source = "git+https://github.com/paritytech/polkadot-sdk#c1238b64431b4c74d88c082099caed36177b5b11" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -10241,14 +10236,14 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#41a5d8ec5f3d3d0ff82899be66113b223395ade5" +source = "git+https://github.com/paritytech/polkadot-sdk#c1238b64431b4c74d88c082099caed36177b5b11" dependencies = [ "Inflector", "expander", "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -10261,7 +10256,7 @@ dependencies = [ "proc-macro-crate 3.2.0", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -10343,12 +10338,12 @@ source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#41a5d8ec5f3d3d0ff82899be66113b223395ade5" +source = "git+https://github.com/paritytech/polkadot-sdk#c1238b64431b4c74d88c082099caed36177b5b11" [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#41a5d8ec5f3d3d0ff82899be66113b223395ade5" +source = "git+https://github.com/paritytech/polkadot-sdk#c1238b64431b4c74d88c082099caed36177b5b11" dependencies = [ "impl-serde 0.5.0", "parity-scale-codec", @@ -10384,7 +10379,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#41a5d8ec5f3d3d0ff82899be66113b223395ade5" +source = "git+https://github.com/paritytech/polkadot-sdk#c1238b64431b4c74d88c082099caed36177b5b11" dependencies = [ "parity-scale-codec", "tracing", @@ -10474,13 +10469,13 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/paritytech/polkadot-sdk#41a5d8ec5f3d3d0ff82899be66113b223395ade5" +source = "git+https://github.com/paritytech/polkadot-sdk#c1238b64431b4c74d88c082099caed36177b5b11" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -10618,7 +10613,7 @@ dependencies = [ "quote", "sqlx-core", "sqlx-macros-core", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -10639,7 +10634,7 @@ dependencies = [ "sha2 0.10.8", "sqlx-core", "sqlx-sqlite", - "syn 2.0.90", + "syn 2.0.87", "tempfile", "tokio", "url", @@ -10806,7 +10801,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -10863,7 +10858,7 @@ version = "0.17.0" source = "git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409#87971b3e92721bdf10bf40b410eaae779d494ca0" dependencies = [ "http-body-util", - "hyper 1.5.0", + "hyper 1.4.1", "hyper-util", "log", "prometheus", @@ -10910,7 +10905,7 @@ dependencies = [ "quote", "rayon", "subtensor-linting", - "syn 2.0.90", + "syn 2.0.87", "walkdir", ] @@ -10946,7 +10941,7 @@ dependencies = [ "proc-macro2", "procedural-fork", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -10956,7 +10951,7 @@ dependencies = [ "ahash 0.8.11", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -10994,9 +10989,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.90" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -11023,7 +11018,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -11114,7 +11109,7 @@ checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -11261,7 +11256,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -11421,7 +11416,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -11867,7 +11862,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -11901,7 +11896,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -12605,7 +12600,7 @@ dependencies = [ "Inflector", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -12665,7 +12660,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] @@ -12685,7 +12680,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.87", ] [[package]] diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 82e6d4e2e..b62ef4f8c 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -93,6 +93,44 @@ mod dispatches { } } + /// --- Allows a hotkey to set weights for multiple netuids as a batch. + /// + /// # Args: + /// * `origin`: (Origin): + /// - The caller, a hotkey who wishes to set their weights. + /// + /// * `netuids` (Vec>): + /// - The network uids we are setting these weights on. + /// + /// * `weights` (Vec, Compact)>): + /// - The weights to set for each network. [(uid, weight), ...] + /// + /// * `version_keys` (Vec>): + /// - The network version keys to check if the validator is up to date. + /// + /// # Event: + /// * WeightsSet; + /// - On successfully setting the weights on chain. + /// * BatchWeightsCompleted; + /// - On success of the batch. + /// * BatchCompletedWithErrors; + /// - On failure of any of the weights in the batch. + /// * BatchWeightItemFailed; + /// - On failure for each failed item in the batch. + /// + #[pallet::call_index(80)] + #[pallet::weight((Weight::from_parts(22_060_000_000, 0) + .saturating_add(T::DbWeight::get().reads(4106)) + .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] + pub fn batch_set_weights( + origin: OriginFor, + netuids: Vec>, + weights: Vec, Compact)>>, + version_keys: Vec>, + ) -> DispatchResult { + Self::do_batch_set_weights(origin, netuids, weights, version_keys) + } + /// ---- Used to commit a hash of your weight values to later be revealed. /// /// # Args: @@ -124,6 +162,40 @@ mod dispatches { Self::do_commit_weights(origin, netuid, commit_hash) } + /// --- Allows a hotkey to commit weight hashes for multiple netuids as a batch. + /// + /// # Args: + /// * `origin`: (Origin): + /// - The caller, a hotkey who wishes to set their weights. + /// + /// * `netuids` (Vec>): + /// - The network uids we are setting these weights on. + /// + /// * `commit_hashes` (Vec): + /// - The commit hashes to commit. + /// + /// # Event: + /// * WeightsSet; + /// - On successfully setting the weights on chain. + /// * BatchWeightsCompleted; + /// - On success of the batch. + /// * BatchCompletedWithErrors; + /// - On failure of any of the weights in the batch. + /// * BatchWeightItemFailed; + /// - On failure for each failed item in the batch. + /// + #[pallet::call_index(100)] + #[pallet::weight((Weight::from_parts(46_000_000, 0) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] + pub fn batch_commit_weights( + origin: OriginFor, + netuids: Vec>, + commit_hashes: Vec, + ) -> DispatchResult { + Self::do_batch_commit_weights(origin, netuids, commit_hashes) + } + /// ---- Used to reveal the weights for a previously committed hash. /// /// # Args: diff --git a/pallets/subtensor/src/macros/errors.rs b/pallets/subtensor/src/macros/errors.rs index 755f86406..ff17aa428 100644 --- a/pallets/subtensor/src/macros/errors.rs +++ b/pallets/subtensor/src/macros/errors.rs @@ -83,7 +83,7 @@ mod errors { /// An axon or prometheus serving exceeded the rate limit for a registered neuron. ServingRateLimitExceeded, /// The caller is attempting to set weights with more UIDs than allowed. - UidsLengthExceedUidsInSubNet, + UidsLengthExceedUidsInSubNet, // 32 /// A transactor exceeded the rate limit for add network transaction. NetworkTxRateLimitExceeded, /// A transactor exceeded the rate limit for delegate transaction. diff --git a/pallets/subtensor/src/macros/events.rs b/pallets/subtensor/src/macros/events.rs index 23d4b11b7..668eae7fe 100644 --- a/pallets/subtensor/src/macros/events.rs +++ b/pallets/subtensor/src/macros/events.rs @@ -4,6 +4,8 @@ use frame_support::pallet_macros::pallet_section; /// This can later be imported into the pallet using [`import_section`]. #[pallet_section] mod events { + use codec::Compact; + #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { @@ -232,5 +234,19 @@ mod events { /// - **netuid**: The network identifier. /// - **revealed_hashes**: A vector of hashes representing each revealed weight set. WeightsBatchRevealed(T::AccountId, u16, Vec), + + /// A batch of weights (or commits) have been force-set. + /// + /// - **netuids**: The netuids these weights were successfully set/committed for. + /// - **who**: The hotkey that set this batch. + BatchWeightsCompleted(Vec>, T::AccountId), + + /// A batch extrinsic completed but with some errors. + BatchCompletedWithErrors(), + + /// A weight set among a batch of weights failed. + /// + /// - **error**: The dispatch error emitted by the failed item. + BatchWeightItemFailed(sp_runtime::DispatchError), } } diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index 0734cfed8..ed7708448 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -1,5 +1,6 @@ use super::*; use crate::epoch::math::*; +use codec::Compact; use sp_core::{ConstU32, H256}; use sp_runtime::{ traits::{BlakeTwo256, Hash}, @@ -108,6 +109,84 @@ impl Pallet { }) } + /// ---- The implementation for the extrinsic batch_commit_weights. + /// + /// This call runs a batch of commit weights calls, continuing on errors. + /// + /// # Args: + /// * 'origin': (RuntimeOrigin): + /// - The signature of the calling hotkey. + /// + /// * 'netuids' ( Vec> ): + /// - The u16 network identifiers. + /// + /// * 'commit_hashes' ( Vec ): + /// - The commit hashes to be committed, one hash for each netuid in the batch. + /// + /// # Event: + /// * WeightsCommitted; + /// - On successfully storing the weight hashes. + /// * BatchCompletedWithErrors; + /// - Emitted when at least on of the weight commits has an error. + /// * BatchWeightItemFailed; + /// - Emitted for each error within the batch. + /// * BatchWeightsCompleted + /// - Emitted when the batch of weights is completed. + /// * InputLengthsUnequal; + /// - Emitted when the lengths of the input vectors are not equal. + /// + pub fn do_batch_commit_weights( + origin: T::RuntimeOrigin, + netuids: Vec>, + commit_hashes: Vec, + ) -> dispatch::DispatchResult { + // --- 1. Check the caller's signature. This is the hotkey of a registered account. + let hotkey = ensure_signed(origin.clone())?; + log::debug!( + "do_batch_commit_weights( origin:{:?}, netuids:{:?}, hashes:{:?} )", + hotkey, + netuids, + commit_hashes + ); + + ensure!( + netuids.len() == commit_hashes.len(), + Error::::InputLengthsUnequal + ); + + let results: Vec = netuids + .iter() + .zip(commit_hashes.iter()) + .map(|(&netuid, &commit_hash)| { + let origin_cloned = origin.clone(); + + Self::do_commit_weights(origin_cloned, netuid.into(), commit_hash) + }) + .collect(); + + let mut completed_with_errors: bool = false; + for result in results { + if let Some(err) = result.err() { + if !completed_with_errors { + Self::deposit_event(Event::BatchCompletedWithErrors()); + completed_with_errors = true; + } + Self::deposit_event(Event::BatchWeightItemFailed(err)); + } + } + + // --- 19. Emit the tracking event. + log::debug!( + "BatchWeightsCompleted( netuids:{:?}, hotkey:{:?} )", + netuids, + hotkey + ); + Self::deposit_event(Event::BatchWeightsCompleted(netuids, hotkey)); + + // --- 20. Return ok. + Ok(()) + } + /// ---- The implementation for committing commit-reveal v3 weights. /// /// # Args: @@ -714,6 +793,104 @@ impl Pallet { Ok(()) } + /// ---- The implementation for the extrinsic batch_set_weights. + /// + /// This call runs a batch of set weights calls, continuing on errors. + /// + /// # Args: + /// * 'origin': (RuntimeOrigin): + /// - The signature of the calling hotkey. + /// + /// * 'netuids' ( Vec> ): + /// - The u16 network identifiers. + /// + /// * 'weights' ( Vec, Compact)>> ): + /// - Tuples of (uid, value) of the weights to be set on the chain, + /// one Vec for each netuid in the batch. + /// + /// * 'version_keys' ( Vec> ): + /// - The network version key, one u64 for each netuid in the batch. + /// + /// # Event: + /// * WeightsSet; + /// - On successfully setting the weights on chain. + /// * BatchCompletedWithErrors; + /// - Emitted when at least on of the weight sets has an error. + /// * BatchWeightItemFailed; + /// - Emitted for each error within the batch. + /// * BatchWeightsCompleted; + /// - Emitted when the batch of weights is completed. + /// * InputLengthsUnequal; + /// - Emitted when the lengths of the input vectors are not equal. + /// + pub fn do_batch_set_weights( + origin: T::RuntimeOrigin, + netuids: Vec>, + weights: Vec, Compact)>>, + version_keys: Vec>, + ) -> dispatch::DispatchResult { + // --- 1. Check the caller's signature. This is the hotkey of a registered account. + let hotkey = ensure_signed(origin.clone())?; + log::debug!( + "do_batch_set_weights( origin:{:?} netuids:{:?}, weights:{:?}", + hotkey, + netuids, + weights + ); + + ensure!( + netuids.len() == weights.len() && netuids.len() == version_keys.len(), + Error::::InputLengthsUnequal + ); + + let results: Vec = netuids + .iter() + .zip(weights.iter()) + .zip(version_keys.iter()) + .map(|((&netuid, w), &version_key)| { + let origin_cloned = origin.clone(); + + if Self::get_commit_reveal_weights_enabled(netuid.into()) { + return Err(Error::::CommitRevealEnabled.into()); + } + + let uids = w.iter().map(|(u, _)| (*u).into()).collect::>(); + + let values = w.iter().map(|(_, v)| (*v).into()).collect::>(); + + Self::do_set_weights( + origin_cloned, + netuid.into(), + uids, + values, + version_key.into(), + ) + }) + .collect(); + + let mut completed_with_errors: bool = false; + for result in results { + if let Some(err) = result.err() { + if !completed_with_errors { + Self::deposit_event(Event::BatchCompletedWithErrors()); + completed_with_errors = true; + } + Self::deposit_event(Event::BatchWeightItemFailed(err)); + } + } + + // --- 19. Emit the tracking event. + log::debug!( + "BatchWeightsSet( netuids:{:?}, hotkey:{:?} )", + netuids, + hotkey + ); + Self::deposit_event(Event::BatchWeightsCompleted(netuids, hotkey)); + + // --- 20. Return ok. + Ok(()) + } + // ========================== // ==== Helper functions ==== // ========================== diff --git a/pallets/subtensor/src/tests/batch_tx.rs b/pallets/subtensor/src/tests/batch_tx.rs index 9a53746cb..5768ee97d 100644 --- a/pallets/subtensor/src/tests/batch_tx.rs +++ b/pallets/subtensor/src/tests/batch_tx.rs @@ -1,6 +1,13 @@ +use codec::Compact; use frame_support::{assert_ok, traits::Currency}; use frame_system::Config; -use sp_core::U256; +use sp_core::{H256, U256}; +use sp_runtime::{ + traits::{BlakeTwo256, Hash}, + DispatchError, +}; + +use crate::{Error, Event}; use super::mock::*; @@ -33,3 +40,360 @@ fn test_batch_txs() { assert_eq!(Balances::total_balance(&charlie), 2_000_000_000); }); } + +// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --test batch_tx -- test_batch_set_weights --exact --nocapture +#[test] +fn test_batch_set_weights() { + // Verify the batch set weights call works + new_test_ext(1).execute_with(|| { + let netuid_0: u16 = 1; + let netuid_1: u16 = 2; + let netuid_2: u16 = 3; + + // Create 3 networks + add_network(netuid_0, 1, 0); + add_network(netuid_1, 2, 0); + add_network(netuid_2, 3, 0); + + let hotkey: U256 = U256::from(2); + let spare_hk: U256 = U256::from(3); + + let coldkey: U256 = U256::from(101); + let spare_ck = U256::from(102); + + let stake_to_give_child = 109_999; + + SubtensorModule::add_balance_to_coldkey_account(&coldkey, stake_to_give_child + 10); + + // Register both hotkeys on each network + register_ok_neuron(netuid_0, hotkey, coldkey, 1); + register_ok_neuron(netuid_0, spare_hk, spare_ck, 1); + + register_ok_neuron(netuid_1, hotkey, coldkey, 1); + register_ok_neuron(netuid_1, spare_hk, spare_ck, 1); + + register_ok_neuron(netuid_2, hotkey, coldkey, 1); + register_ok_neuron(netuid_2, spare_hk, spare_ck, 1); + + // Increase stake on hotkey setting the weights + SubtensorModule::increase_stake_on_coldkey_hotkey_account( + &coldkey, + &hotkey, + stake_to_give_child, + ); + + // Set the rate limit to 0 for all networks + SubtensorModule::set_weights_set_rate_limit(netuid_0, 0); + SubtensorModule::set_weights_set_rate_limit(netuid_1, 0); + SubtensorModule::set_weights_set_rate_limit(netuid_2, 0); + + // Has stake and no parent + step_block(7200 + 1); + + // Set weights on the other hotkey and Use maximum value for u16 + let weights: Vec<(Compact, Compact)> = vec![(Compact(1), Compact(u16::MAX))]; + let version_key_0: Compact = SubtensorModule::get_weights_version_key(netuid_0).into(); + let version_key_1: Compact = SubtensorModule::get_weights_version_key(netuid_1).into(); + let version_key_2: Compact = SubtensorModule::get_weights_version_key(netuid_2).into(); + + // Set the min stake very high + SubtensorModule::set_stake_threshold(stake_to_give_child * 5); + + // Check the key has less stake than required + assert!( + SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid_0) + < SubtensorModule::get_stake_threshold() + ); + + let netuids_vec: Vec> = + vec![netuid_0.into(), netuid_1.into(), netuid_2.into()]; + + // Check the batch succeeds (force set weights) + assert_ok!(SubtensorModule::batch_set_weights( + RuntimeOrigin::signed(hotkey), + netuids_vec.clone(), + vec![weights.clone(), weights.clone(), weights.clone()], // One per network + vec![version_key_0, version_key_1, version_key_2] + )); + + // Check the events are emitted, three errors about not enough stake + // Also events for batch completed with errors and batch complete with errors + assert!(System::events().iter().any(|event| matches!( + event.event.clone(), + RuntimeEvent::SubtensorModule(Event::BatchWeightsCompleted { .. }) + ))); + assert!(System::events().iter().any(|event| matches!( + event.event.clone(), + RuntimeEvent::SubtensorModule(Event::BatchCompletedWithErrors { .. }) + ))); + + let expected_err: DispatchError = Error::::NotEnoughStakeToSetWeights.into(); + + assert_eq!( + System::events() + .iter() + .filter(|event| match event.event { + RuntimeEvent::SubtensorModule(Event::BatchWeightItemFailed(err)) => + err == expected_err, + _ => false, + }) + .collect::>() + .len(), + 3, // Three not enough stake errors + "{:?}", + System::events() + ); + + // Reset the events + System::reset_events(); + + assert!(!SubtensorModule::check_weights_min_stake(&hotkey, netuid_0)); + + // Set a minimum stake to set weights + SubtensorModule::set_stake_threshold(stake_to_give_child - 5); + + // Check if the stake for the hotkey is above + assert!( + SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid_0) + >= SubtensorModule::get_stake_threshold() + ); + + // Try with enough stake + assert_ok!(SubtensorModule::batch_set_weights( + RuntimeOrigin::signed(hotkey), + netuids_vec.clone(), + vec![weights.clone(), weights.clone(), weights.clone()], + vec![version_key_0, version_key_1, version_key_2] + )); + + assert!(SubtensorModule::check_weights_min_stake(&hotkey, netuid_0)); + + // Check the events are emitted, no errors + assert!(System::events().iter().any(|event| matches!( + event.event, + RuntimeEvent::SubtensorModule(Event::BatchWeightsCompleted { .. }) + ))); + + // No errors + assert!(!System::events().iter().any(|event| matches!( + event.event, + RuntimeEvent::SubtensorModule(Event::BatchCompletedWithErrors { .. }) + ))); + assert!(!System::events().iter().any(|event| matches!( + event.event, + RuntimeEvent::SubtensorModule(Event::BatchWeightItemFailed { .. }) + ))); + + // Reset events + System::reset_events(); + + // Test again, but with only one failure, different reason + // Set version key higher for just one network + SubtensorModule::set_weights_version_key(netuid_2, u64::from(version_key_2) + 1_u64); + // Verify the version key is *not* correct + assert!(!SubtensorModule::check_version_key( + netuid_2, + version_key_2.into() + )); + assert_ok!(SubtensorModule::batch_set_weights( + RuntimeOrigin::signed(hotkey), + netuids_vec.clone(), + vec![weights.clone(), weights.clone(), weights.clone()], + vec![version_key_0, version_key_1, version_key_2] // Version key 2 is not correct + )); + + // Check the events are emitted, one error + assert!(System::events().iter().any(|event| matches!( + event.event, + RuntimeEvent::SubtensorModule(Event::BatchWeightsCompleted { .. }) + ))); + assert!(System::events().iter().any(|event| matches!( + event.event, + RuntimeEvent::SubtensorModule(Event::BatchCompletedWithErrors { .. }) + ))); + + // Only one error + assert_eq!( + System::events() + .iter() + .filter(|event| matches!( + event.event, + RuntimeEvent::SubtensorModule(Event::BatchWeightItemFailed(..)) + )) + .collect::>() + .len(), + 1 + ); + }); +} + +// SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --test batch_tx -- test_batch_commit_weights --exact --nocapture +#[test] +fn test_batch_commit_weights() { + // Verify the batch set weights call works + new_test_ext(1).execute_with(|| { + let netuid_0: u16 = 1; + let netuid_1: u16 = 2; + let netuid_2: u16 = 3; + + // Create 3 networks + add_network(netuid_0, 1, 0); + add_network(netuid_1, 1, 0); + add_network(netuid_2, 1, 0); + + let hotkey: U256 = U256::from(2); + let spare_hk: U256 = U256::from(3); + + let coldkey: U256 = U256::from(101); + let spare_ck = U256::from(102); + + let stake_to_give_child = 109_999; + + SubtensorModule::add_balance_to_coldkey_account(&coldkey, stake_to_give_child + 10); + + // Register both hotkeys on each network + register_ok_neuron(netuid_0, hotkey, coldkey, 1); + register_ok_neuron(netuid_0, spare_hk, spare_ck, 1); + + register_ok_neuron(netuid_1, hotkey, coldkey, 1); + register_ok_neuron(netuid_1, spare_hk, spare_ck, 1); + + register_ok_neuron(netuid_2, hotkey, coldkey, 1); + register_ok_neuron(netuid_2, spare_hk, spare_ck, 1); + + // Increase stake on hotkey setting the weights + SubtensorModule::increase_stake_on_coldkey_hotkey_account( + &coldkey, + &hotkey, + stake_to_give_child, + ); + + // Set the rate limit to 0 for all networks + SubtensorModule::set_weights_set_rate_limit(netuid_0, 0); + SubtensorModule::set_weights_set_rate_limit(netuid_1, 0); + SubtensorModule::set_weights_set_rate_limit(netuid_2, 0); + + // Disable commit reveal for all networks (pre-emptively) + SubtensorModule::set_commit_reveal_weights_enabled(netuid_0, false); + SubtensorModule::set_commit_reveal_weights_enabled(netuid_1, false); + SubtensorModule::set_commit_reveal_weights_enabled(netuid_2, false); + + // Has stake and no parent + step_block(7200 + 1); + + let hash: H256 = BlakeTwo256::hash_of(&vec![1, 2, 3]); + + let netuids_vec: Vec> = + vec![netuid_0.into(), netuid_1.into(), netuid_2.into()]; + + // Check the batch succeeds (force commit weights) + assert_ok!(SubtensorModule::batch_commit_weights( + RuntimeOrigin::signed(hotkey), + netuids_vec.clone(), + vec![hash, hash, hash], // One per network + )); + + // Check the events are emitted, three errors about commit reveal disabled + // Also events for batch completed with errors and batch complete with errors + assert!(System::events().iter().any(|event| matches!( + event.event.clone(), + RuntimeEvent::SubtensorModule(Event::BatchWeightsCompleted { .. }) + ))); + assert!(System::events().iter().any(|event| matches!( + event.event.clone(), + RuntimeEvent::SubtensorModule(Event::BatchCompletedWithErrors { .. }) + ))); + + let expected_err: DispatchError = Error::::CommitRevealDisabled.into(); + + assert_eq!( + System::events() + .iter() + .filter(|event| match event.event { + RuntimeEvent::SubtensorModule(Event::BatchWeightItemFailed(err)) => + err == expected_err, + _ => false, + }) + .collect::>() + .len(), + 3 // Three commit reveal disabled errors + ); + + // Reset the events + System::reset_events(); + + // Enable commit reveal for all networks + SubtensorModule::set_commit_reveal_weights_enabled(netuid_0, true); + SubtensorModule::set_commit_reveal_weights_enabled(netuid_1, true); + SubtensorModule::set_commit_reveal_weights_enabled(netuid_2, true); + + // Set a minimum stake to set weights + SubtensorModule::set_stake_threshold(stake_to_give_child - 5); + + // Check if the stake for the hotkey is above + assert!( + SubtensorModule::get_stake_for_hotkey_on_subnet(&hotkey, netuid_0) + >= SubtensorModule::get_stake_threshold() + ); + + // Try with commit reveal enabled + assert_ok!(SubtensorModule::batch_commit_weights( + RuntimeOrigin::signed(hotkey), + netuids_vec.clone(), + vec![hash, hash, hash] + )); + + assert!(SubtensorModule::check_weights_min_stake(&hotkey, netuid_0)); + + // Check the events are emitted, no errors + assert!(System::events().iter().any(|event| matches!( + event.event, + RuntimeEvent::SubtensorModule(Event::BatchWeightsCompleted { .. }) + ))); + + // No errors + assert!(!System::events().iter().any(|event| matches!( + event.event, + RuntimeEvent::SubtensorModule(Event::BatchCompletedWithErrors { .. }) + ))); + assert!(!System::events().iter().any(|event| matches!( + event.event, + RuntimeEvent::SubtensorModule(Event::BatchWeightItemFailed { .. }) + ))); + + // Reset events + System::reset_events(); + + // Test again, but with only one failure, different reason + // Disable commit reveal for one network + SubtensorModule::set_commit_reveal_weights_enabled(netuid_2, false); + assert_ok!(SubtensorModule::batch_commit_weights( + RuntimeOrigin::signed(hotkey), + netuids_vec.clone(), + vec![hash, hash, hash] + )); + + // Check the events are emitted, one error + assert!(System::events().iter().any(|event| matches!( + event.event, + RuntimeEvent::SubtensorModule(Event::BatchWeightsCompleted { .. }) + ))); + assert!(System::events().iter().any(|event| matches!( + event.event, + RuntimeEvent::SubtensorModule(Event::BatchCompletedWithErrors { .. }) + ))); + + // Only one error + assert_eq!( + System::events() + .iter() + .filter(|event| matches!( + event.event, + RuntimeEvent::SubtensorModule(Event::BatchWeightItemFailed(..)) + )) + .collect::>() + .len(), + 1 + ); + }); +}