From 24866d3c4a6f93df8f47767f7c8245e2871d0350 Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 28 Oct 2024 10:52:10 +0200 Subject: [PATCH 01/36] Main implementation of child bounty index by parent bounty --- Cargo.lock | 232 +++++++++--------- .../frame/child-bounties/src/benchmarking.rs | 8 +- substrate/frame/child-bounties/src/lib.rs | 55 +++-- substrate/frame/child-bounties/src/tests.rs | 4 +- 4 files changed, 162 insertions(+), 137 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3d5193fe0ee8b..dafe4e3fa81ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,7 +168,7 @@ dependencies = [ "proc-macro-error", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", "syn-solidity", "tiny-keccak", ] @@ -295,7 +295,7 @@ dependencies = [ "proc-macro-error", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -753,7 +753,7 @@ checksum = "7378575ff571966e99a744addeff0bff98b8ada0dedf1956d59e634db95eaac1" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", "synstructure 0.13.1", ] @@ -776,7 +776,7 @@ checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -1385,7 +1385,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -1402,7 +1402,7 @@ checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -1617,7 +1617,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -3059,7 +3059,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -4417,7 +4417,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -4970,7 +4970,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5010,7 +5010,7 @@ dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", "scratch", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5027,7 +5027,7 @@ checksum = "50c49547d73ba8dcfd4ad7325d64c6d5391ff4224d498fc39a6f3f49825a530d" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5075,7 +5075,7 @@ dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", "strsim 0.11.1", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5097,7 +5097,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core 0.20.10", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5214,7 +5214,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5225,7 +5225,7 @@ checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5236,7 +5236,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5344,7 +5344,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5405,7 +5405,7 @@ dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", "regex", - "syn 2.0.82", + "syn 2.0.85", "termcolor", "toml 0.8.12", "walkdir", @@ -5637,7 +5637,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5657,7 +5657,7 @@ checksum = "5e9a1f9f7d83e59740248a6e14ecf93929ade55027844dfcea78beafccc15745" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5668,7 +5668,7 @@ checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5883,7 +5883,7 @@ dependencies = [ "prettyplease", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -5955,7 +5955,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -6298,7 +6298,7 @@ dependencies = [ "quote 1.0.37", "scale-info", "sp-arithmetic 23.0.0", - "syn 2.0.82", + "syn 2.0.85", "trybuild", ] @@ -6514,7 +6514,7 @@ dependencies = [ "sp-metadata-ir 0.6.0", "sp-runtime 31.0.1", "static_assertions", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -6525,7 +6525,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -6534,7 +6534,7 @@ version = "11.0.0" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -6788,7 +6788,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -7510,7 +7510,7 @@ dependencies = [ "hyper 1.3.1", "hyper-util", "log", - "rustls 0.23.14", + "rustls 0.23.15", "rustls-native-certs 0.8.0", "rustls-pki-types", "tokio", @@ -8149,7 +8149,7 @@ dependencies = [ "http 1.1.0", "jsonrpsee-core 0.23.2", "pin-project", - "rustls 0.23.14", + "rustls 0.23.15", "rustls-pki-types", "rustls-platform-verifier", "soketto 0.8.0", @@ -8174,7 +8174,7 @@ dependencies = [ "http 1.1.0", "jsonrpsee-core 0.24.3", "pin-project", - "rustls 0.23.14", + "rustls 0.23.15", "rustls-pki-types", "rustls-platform-verifier", "soketto 0.8.0", @@ -8292,7 +8292,7 @@ dependencies = [ "hyper-util", "jsonrpsee-core 0.24.3", "jsonrpsee-types 0.24.3", - "rustls 0.23.14", + "rustls 0.23.15", "rustls-platform-verifier", "serde", "serde_json", @@ -8313,7 +8313,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -9067,7 +9067,7 @@ dependencies = [ "proc-macro-warning 0.4.2", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -9475,7 +9475,7 @@ dependencies = [ "macro_magic_core", "macro_magic_macros", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -9489,7 +9489,7 @@ dependencies = [ "macro_magic_core_macros", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -9500,7 +9500,7 @@ checksum = "b02abfe41815b5bd98dbd4260173db2c116dda171dc0fe7838cb206333b83308" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -9511,7 +9511,7 @@ checksum = "73ea28ee64b88876bf45277ed9a5817c1817df061a74f2b988971a12570e5869" dependencies = [ "macro_magic_core", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -9848,7 +9848,7 @@ dependencies = [ "cfg-if", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -10453,7 +10453,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -10629,7 +10629,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -11401,7 +11401,7 @@ version = "18.0.0" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -12530,7 +12530,7 @@ version = "0.1.0" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -12775,7 +12775,7 @@ dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", "sp-runtime 31.0.1", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -13790,7 +13790,7 @@ dependencies = [ "pest_meta", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -13831,7 +13831,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16339,7 +16339,7 @@ dependencies = [ "polkavm-common 0.8.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16351,7 +16351,7 @@ dependencies = [ "polkavm-common 0.9.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16363,7 +16363,7 @@ dependencies = [ "polkavm-common 0.13.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16373,7 +16373,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15e85319a0d5129dc9f021c62607e0804f5fb777a05cdda44d750ac0732def66" dependencies = [ "polkavm-derive-impl 0.8.0", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16383,7 +16383,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl 0.9.0", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16393,7 +16393,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6f3ad876ca1855038c21d48cbe35164552208a54b21f8295a7d76bc33ef1e38" dependencies = [ "polkavm-derive-impl 0.13.0", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16610,7 +16610,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c64d9ba0963cdcea2e1b2230fbae2bab30eb25a174be395c41e764bfb65dd62" dependencies = [ "proc-macro2 1.0.86", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16715,7 +16715,7 @@ checksum = "3d1eaa7fa0aa1929ffdf7eeb6eac234dde6268914a14ad44d23521ab6a9b258e" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16726,7 +16726,7 @@ checksum = "9b698b0b09d40e9b7c1a47b132d66a8b54bcd20583d9b6d06e4535e383b4405c" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16807,7 +16807,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16879,8 +16879,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8650aabb6c35b860610e9cff5dc1af886c9e25073b7b1712a68972af4281302" dependencies = [ "bytes", - "heck 0.4.1", - "itertools 0.10.5", + "heck 0.5.0", + "itertools 0.12.1", "log", "multimap", "once_cell", @@ -16889,7 +16889,7 @@ dependencies = [ "prost 0.13.2", "prost-types", "regex", - "syn 2.0.82", + "syn 2.0.85", "tempfile", ] @@ -16913,10 +16913,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.12.1", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16926,10 +16926,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acf0c195eebb4af52c752bec4f52f645da98b6e92077a04110c7f349477ae5ac" dependencies = [ "anyhow", - "itertools 0.10.5", + "itertools 0.12.1", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -17084,7 +17084,7 @@ dependencies = [ "quinn-proto 0.11.8", "quinn-udp 0.5.4", "rustc-hash 2.0.0", - "rustls 0.23.14", + "rustls 0.23.15", "socket2 0.5.7", "thiserror", "tokio", @@ -17118,7 +17118,7 @@ dependencies = [ "rand", "ring 0.17.7", "rustc-hash 2.0.0", - "rustls 0.23.14", + "rustls 0.23.15", "slab", "thiserror", "tinyvec", @@ -17389,7 +17389,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -17621,7 +17621,7 @@ dependencies = [ "percent-encoding", "pin-project-lite", "quinn 0.11.5", - "rustls 0.23.14", + "rustls 0.23.15", "rustls-pemfile 2.0.0", "rustls-pki-types", "serde", @@ -18008,7 +18008,7 @@ dependencies = [ "regex", "relative-path", "rustc_version 0.4.0", - "syn 2.0.82", + "syn 2.0.85", "unicode-ident", ] @@ -18207,9 +18207,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.14" +version = "0.23.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +checksum = "5fbb44d7acc4e873d613422379f69f237a1b141928c02f6bc6ccfddddc2d7993" dependencies = [ "log", "once_cell", @@ -18279,9 +18279,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" +checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" [[package]] name = "rustls-platform-verifier" @@ -18294,7 +18294,7 @@ dependencies = [ "jni", "log", "once_cell", - "rustls 0.23.14", + "rustls 0.23.15", "rustls-native-certs 0.7.0", "rustls-platform-verifier-android", "rustls-webpki 0.102.8", @@ -18549,7 +18549,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -19509,7 +19509,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.3", "rand", - "rustls 0.23.14", + "rustls 0.23.15", "sc-block-builder", "sc-client-api", "sc-client-db", @@ -19914,7 +19914,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -20097,7 +20097,7 @@ dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", "scale-info", - "syn 2.0.82", + "syn 2.0.85", "thiserror", ] @@ -20419,7 +20419,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -20521,7 +20521,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -21492,7 +21492,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -21507,7 +21507,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -22117,7 +22117,7 @@ version = "0.1.0" dependencies = [ "quote 1.0.37", "sp-crypto-hashing 0.1.0", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -22128,7 +22128,7 @@ checksum = "b85d0f1f1e44bd8617eb2a48203ee854981229e3e79e6f468c7175d5fd37489b" dependencies = [ "quote 1.0.37", "sp-crypto-hashing 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -22146,7 +22146,7 @@ source = "git+https://github.com/paritytech/polkadot-sdk#82912acb33a9030c0ef3bf5 dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -22155,7 +22155,7 @@ version = "14.0.0" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -22166,7 +22166,7 @@ checksum = "48d09fa0a5f7299fb81ee25ae3853d26200f7a348148aed6de76be905c007dbe" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -22728,7 +22728,7 @@ dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -22740,7 +22740,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -22754,7 +22754,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -23229,7 +23229,7 @@ dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", "sp-version 29.0.0", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -23241,7 +23241,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -23708,7 +23708,7 @@ dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", "rustversion", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -23721,7 +23721,7 @@ dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", "rustversion", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -24210,7 +24210,7 @@ dependencies = [ "scale-info", "scale-typegen", "subxt-metadata", - "syn 2.0.82", + "syn 2.0.85", "thiserror", "tokio", ] @@ -24273,7 +24273,7 @@ dependencies = [ "quote 1.0.37", "scale-typegen", "subxt-codegen", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -24428,9 +24428,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.82" +version = "2.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" +checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", @@ -24446,7 +24446,7 @@ dependencies = [ "paste", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -24475,7 +24475,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -24605,7 +24605,7 @@ checksum = "5999e24eaa32083191ba4e425deb75cdf25efefabe5aaccb7446dd0d4122a3f5" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -24745,9 +24745,9 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.64" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ "thiserror-impl", ] @@ -24774,13 +24774,13 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "1.0.64" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -24942,7 +24942,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -24993,7 +24993,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls 0.23.14", + "rustls 0.23.15", "rustls-pki-types", "tokio", ] @@ -25218,7 +25218,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -25260,7 +25260,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -25717,7 +25717,7 @@ dependencies = [ "flate2", "log", "once_cell", - "rustls 0.23.14", + "rustls 0.23.15", "rustls-pki-types", "serde", "serde_json", @@ -25912,7 +25912,7 @@ dependencies = [ "once_cell", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", "wasm-bindgen-shared", ] @@ -25946,7 +25946,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -27081,7 +27081,7 @@ dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", "staging-xcm", - "syn 2.0.82", + "syn 2.0.85", "trybuild", ] @@ -27252,7 +27252,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -27272,7 +27272,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] diff --git a/substrate/frame/child-bounties/src/benchmarking.rs b/substrate/frame/child-bounties/src/benchmarking.rs index b1f6370f33405..bfbbe50ce23ec 100644 --- a/substrate/frame/child-bounties/src/benchmarking.rs +++ b/substrate/frame/child-bounties/src/benchmarking.rs @@ -145,7 +145,7 @@ fn activate_child_bounty( bounty_setup.reason.clone(), )?; - bounty_setup.child_bounty_id = ChildBountyCount::::get() - 1; + bounty_setup.child_bounty_id = ParentTotalChildBounties::::get(bounty_setup.bounty_id) - 1; ChildBounties::::propose_curator( RawOrigin::Signed(bounty_setup.curator.clone()).into(), @@ -199,7 +199,7 @@ benchmarks! { bounty_setup.child_bounty_value, bounty_setup.reason.clone(), )?; - let child_bounty_id = ChildBountyCount::::get() - 1; + let child_bounty_id = ParentTotalChildBounties::::get(bounty_setup.bounty_id) - 1; }: _(RawOrigin::Signed(bounty_setup.curator), bounty_setup.bounty_id, child_bounty_id, child_curator_lookup, bounty_setup.child_bounty_fee) @@ -215,7 +215,7 @@ benchmarks! { bounty_setup.child_bounty_value, bounty_setup.reason.clone(), )?; - bounty_setup.child_bounty_id = ChildBountyCount::::get() - 1; + bounty_setup.child_bounty_id = ParentTotalChildBounties::::get(bounty_setup.bounty_id) - 1; ChildBounties::::propose_curator( RawOrigin::Signed(bounty_setup.curator.clone()).into(), @@ -290,7 +290,7 @@ benchmarks! { bounty_setup.child_bounty_value, bounty_setup.reason.clone(), )?; - bounty_setup.child_bounty_id = ChildBountyCount::::get() - 1; + bounty_setup.child_bounty_id = ParentTotalChildBounties::::get(bounty_setup.bounty_id) - 1; }: close_child_bounty(RawOrigin::Root, bounty_setup.bounty_id, bounty_setup.child_bounty_id) diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 660a30ca5d264..88874ba6f8069 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -181,16 +181,22 @@ pub mod pallet { Canceled { index: BountyIndex, child_index: BountyIndex }, } - /// Number of total child bounties. + /// DEPRECATED: Replaced with `ParentTotalChildBounties` storage item keeping dedicated counts + /// for each parent bounty. Number of total child bounties. #[pallet::storage] pub type ChildBountyCount = StorageValue<_, BountyIndex, ValueQuery>; - /// Number of child bounties per parent bounty. + /// Number of active child bounties per parent bounty. /// Map of parent bounty index to number of child bounties. #[pallet::storage] pub type ParentChildBounties = StorageMap<_, Twox64Concat, BountyIndex, u32, ValueQuery>; + /// Number of total child bounties per parent bounty, including completed bounties. + #[pallet::storage] + pub type ParentTotalChildBounties = + StorageMap<_, Twox64Concat, BountyIndex, u32, ValueQuery>; + /// Child bounties that have been added. #[pallet::storage] pub type ChildBounties = StorageDoubleMap< @@ -204,13 +210,26 @@ pub mod pallet { /// The description of each child-bounty. #[pallet::storage] - pub type ChildBountyDescriptions = - StorageMap<_, Twox64Concat, BountyIndex, BoundedVec>; + pub type ChildBountyDescriptions = StorageDoubleMap< + _, + Twox64Concat, + BountyIndex, + Twox64Concat, + BountyIndex, + BoundedVec, + >; /// The cumulative child-bounty curator fee for each parent bounty. #[pallet::storage] - pub type ChildrenCuratorFees = - StorageMap<_, Twox64Concat, BountyIndex, BalanceOf, ValueQuery>; + pub type ChildrenCuratorFees = StorageDoubleMap< + _, + Twox64Concat, + BountyIndex, + Twox64Concat, + BountyIndex, + BalanceOf, + ValueQuery, + >; #[pallet::call] impl Pallet { @@ -273,7 +292,7 @@ pub mod pallet { )?; // Get child-bounty ID. - let child_bounty_id = ChildBountyCount::::get(); + let child_bounty_id = ParentTotalChildBounties::::get(parent_bounty_id); let child_bounty_account = Self::child_bounty_account_id(child_bounty_id); // Transfer funds from parent bounty to child-bounty. @@ -281,7 +300,10 @@ pub mod pallet { // Increment the active child-bounty count. ParentChildBounties::::mutate(parent_bounty_id, |count| count.saturating_inc()); - ChildBountyCount::::put(child_bounty_id.saturating_add(1)); + ParentTotalChildBounties::::insert( + parent_bounty_id, + child_bounty_id.saturating_add(1), + ); // Create child-bounty instance. Self::create_child_bounty( @@ -343,7 +365,7 @@ pub mod pallet { // Add child-bounty curator fee to the cumulative sum. To be // subtracted from the parent bounty curator when claiming // bounty. - ChildrenCuratorFees::::mutate(parent_bounty_id, |value| { + ChildrenCuratorFees::::mutate(parent_bounty_id, child_bounty_id, |value| { *value = value.saturating_add(fee) }); @@ -713,7 +735,7 @@ pub mod pallet { }); // Remove the child-bounty description. - ChildBountyDescriptions::::remove(child_bounty_id); + ChildBountyDescriptions::::remove(parent_bounty_id, child_bounty_id); // Remove the child-bounty instance from the state. *maybe_child_bounty = None; @@ -808,7 +830,7 @@ impl Pallet { status: ChildBountyStatus::Added, }; ChildBounties::::insert(parent_bounty_id, child_bounty_id, &child_bounty); - ChildBountyDescriptions::::insert(child_bounty_id, description); + ChildBountyDescriptions::::insert(parent_bounty_id, child_bounty_id, description); Self::deposit_event(Event::Added { index: parent_bounty_id, child_index: child_bounty_id }); } @@ -857,7 +879,7 @@ impl Pallet { // Revert the curator fee back to parent bounty curator & // reduce the active child-bounty count. - ChildrenCuratorFees::::mutate(parent_bounty_id, |value| { + ChildrenCuratorFees::::mutate(parent_bounty_id, child_bounty_id, |value| { *value = value.saturating_sub(child_bounty.fee) }); ParentChildBounties::::mutate(parent_bounty_id, |count| { @@ -878,7 +900,7 @@ impl Pallet { debug_assert!(transfer_result.is_ok()); // Remove the child-bounty description. - ChildBountyDescriptions::::remove(child_bounty_id); + ChildBountyDescriptions::::remove(parent_bounty_id, child_bounty_id); *maybe_child_bounty = None; @@ -905,8 +927,11 @@ impl pallet_bounties::ChildBountyManager> for Pallet fn children_curator_fees(bounty_id: pallet_bounties::BountyIndex) -> BalanceOf { // This is asked for when the parent bounty is being claimed. No use of // keeping it in state after that. Hence removing. - let children_fee_total = ChildrenCuratorFees::::get(bounty_id); - ChildrenCuratorFees::::remove(bounty_id); + let mut children_fee_total = 0u32.into(); + for child_fee in ChildrenCuratorFees::::iter_prefix_values(bounty_id) { + children_fee_total += child_fee; + } + ChildrenCuratorFees::::drain_prefix(bounty_id); children_fee_total } } diff --git a/substrate/frame/child-bounties/src/tests.rs b/substrate/frame/child-bounties/src/tests.rs index 125844fa70e2c..c0948402ee058 100644 --- a/substrate/frame/child-bounties/src/tests.rs +++ b/substrate/frame/child-bounties/src/tests.rs @@ -263,7 +263,7 @@ fn add_child_bounty() { // Check the child-bounty description status. assert_eq!( - pallet_child_bounties::ChildBountyDescriptions::::get(0).unwrap(), + pallet_child_bounties::ChildBountyDescriptions::::get(0, 0).unwrap(), b"12345-p1".to_vec(), ); }); @@ -1222,7 +1222,7 @@ fn children_curator_fee_calculation_test() { // Propose curator for child-bounty. assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee)); // Check curator fee added to the sum. - assert_eq!(pallet_child_bounties::ChildrenCuratorFees::::get(0), fee); + assert_eq!(pallet_child_bounties::ChildrenCuratorFees::::get(0, 0), fee); // Accept curator for child-bounty. assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0)); // Award child-bounty. From 811c61aa1af6fbe4470807cb255e56d597d8fb1b Mon Sep 17 00:00:00 2001 From: DavidK Date: Tue, 29 Oct 2024 10:20:42 +0200 Subject: [PATCH 02/36] Migration sketch --- substrate/frame/child-bounties/src/lib.rs | 1 + .../frame/child-bounties/src/migration.rs | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 substrate/frame/child-bounties/src/migration.rs diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 88874ba6f8069..fc25b7173b89c 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -55,6 +55,7 @@ mod benchmarking; mod tests; pub mod weights; +pub mod migration; extern crate alloc; diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs new file mode 100644 index 0000000000000..27727d5557e40 --- /dev/null +++ b/substrate/frame/child-bounties/src/migration.rs @@ -0,0 +1,74 @@ +use super::*; +// use codec::{Decode, Encode}; +use core::marker::PhantomData; +use frame_support::{traits::{Get, UncheckedOnRuntimeUpgrade}, storage_alias}; + +#[cfg(feature = "try-runtime")] +use alloc::vec::Vec; +#[cfg(feature = "try-runtime")] +use frame_support::ensure; + +mod v1 { + use super::*; + + pub struct MigrateToV1Impl(PhantomData); + + #[storage_alias] + type ChildBountyDescriptions = + StorageMap, Twox64Concat, BountyIndex, BoundedVec::MaximumReasonLength>>; + + #[storage_alias] + type ChildrenCuratorFees = + StorageMap, Twox64Concat, BountyIndex, BalanceOf, ValueQuery>; + + impl UncheckedOnRuntimeUpgrade for MigrateToV1Impl { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + let mut reads = 0u64; + let mut writes = 0u64; + for (parent_bounty_id, old_child_bounty_id) in ChildBounties::::iter_keys() { + reads += 1; + let bounty_description = v1::ChildBountyDescriptions::::take(old_child_bounty_id); + writes += 1; + let bounty_curator_fee = v1::ChildrenCuratorFees::::take(old_child_bounty_id); + writes += 1; + let new_child_bounty_id = ParentTotalChildBounties::::get(parent_bounty_id); + reads += 1; + ParentTotalChildBounties::::insert(parent_bounty_id, new_child_bounty_id.saturating_add(1)); + writes += 1; + // should always be Some + writes += 1; + if let Some(taken) = ChildBounties::::take(parent_bounty_id, old_child_bounty_id) { + writes += 1; + ChildBounties::::insert(parent_bounty_id, new_child_bounty_id, taken); + } + if let Some(bounty_description) = bounty_description { + writes += 1; + super::super::ChildBountyDescriptions::::insert(parent_bounty_id, new_child_bounty_id, bounty_description); + } + writes += 1; + super::super::ChildrenCuratorFees::::insert(parent_bounty_id, new_child_bounty_id, bounty_curator_fee); + } + + T::DbWeight::get().reads_writes(reads, writes) + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { + Ok(().encode()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { + Ok(()) + } + } +} + +/// Migrate the pallet storage from `0` to `1`. +pub type MigrateV0ToV1 = frame_support::migrations::VersionedMigration< + 0, + 1, + v1::MigrateToV1Impl, + Pallet, + ::DbWeight, +>; \ No newline at end of file From c1378f16ac85a9bf618dc0f5190572545a8c989d Mon Sep 17 00:00:00 2001 From: DavidK Date: Wed, 30 Oct 2024 10:48:02 +0200 Subject: [PATCH 03/36] Migration with in memory bounties collection --- polkadot/runtime/rococo/src/lib.rs | 3 +- substrate/frame/child-bounties/src/lib.rs | 9 +- .../frame/child-bounties/src/migration.rs | 133 +++++++++++++++--- 3 files changed, 120 insertions(+), 25 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 44dd820f8c3cc..6cc834e33a2e9 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -171,7 +171,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("rococo"), impl_name: create_runtime_str!("parity-rococo-v2.0"), authoring_version: 0, - spec_version: 1_016_001, + spec_version: 1_016_002, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 26, @@ -1683,6 +1683,7 @@ pub mod migrations { paras_registrar::migration::MigrateToV1, pallet_referenda::migration::v1::MigrateV0ToV1, pallet_referenda::migration::v1::MigrateV0ToV1, + pallet_child_bounties::migration::MigrateV0ToV1, // Unlock & unreserve Gov1 funds diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index fc25b7173b89c..846d4c9d152f7 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -53,12 +53,15 @@ #![cfg_attr(not(feature = "std"), no_std)] mod benchmarking; +pub mod migration; mod tests; pub mod weights; -pub mod migration; extern crate alloc; +/// The log target for this pallet. +const LOG_TARGET: &str = "runtime::child-bounties"; + use alloc::vec::Vec; use frame_support::traits::{ @@ -132,7 +135,11 @@ pub mod pallet { use super::*; + /// The in-code storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::config] diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs index 27727d5557e40..69510db233bf6 100644 --- a/substrate/frame/child-bounties/src/migration.rs +++ b/substrate/frame/child-bounties/src/migration.rs @@ -1,64 +1,151 @@ use super::*; // use codec::{Decode, Encode}; use core::marker::PhantomData; -use frame_support::{traits::{Get, UncheckedOnRuntimeUpgrade}, storage_alias}; +use frame_support::{ + storage_alias, + traits::{Get, UncheckedOnRuntimeUpgrade}, +}; #[cfg(feature = "try-runtime")] use alloc::vec::Vec; #[cfg(feature = "try-runtime")] use frame_support::ensure; -mod v1 { - use super::*; +pub mod v1 { + use super::*; pub struct MigrateToV1Impl(PhantomData); - - #[storage_alias] - type ChildBountyDescriptions = - StorageMap, Twox64Concat, BountyIndex, BoundedVec::MaximumReasonLength>>; - - #[storage_alias] - type ChildrenCuratorFees = - StorageMap, Twox64Concat, BountyIndex, BalanceOf, ValueQuery>; + + #[storage_alias] + type ChildBountyDescriptions = StorageMap< + Pallet, + Twox64Concat, + BountyIndex, + BoundedVec::MaximumReasonLength>, + >; + + #[storage_alias] + type ChildrenCuratorFees = + StorageMap, Twox64Concat, BountyIndex, BalanceOf, ValueQuery>; impl UncheckedOnRuntimeUpgrade for MigrateToV1Impl { fn on_runtime_upgrade() -> frame_support::weights::Weight { + // increment reads/writes after the action let mut reads = 0u64; let mut writes = 0u64; + + let mut old_bounty_ids = Vec::new(); + // first iteration collect all existing ids not to mutate map as we iterate it for (parent_bounty_id, old_child_bounty_id) in ChildBounties::::iter_keys() { reads += 1; - let bounty_description = v1::ChildBountyDescriptions::::take(old_child_bounty_id); - writes += 1; - let bounty_curator_fee = v1::ChildrenCuratorFees::::take(old_child_bounty_id); - writes += 1; + old_bounty_ids.push((parent_bounty_id, old_child_bounty_id)); + } + + log::info!( + target: LOG_TARGET, + "Migrating {} child bounties", + old_bounty_ids.len(), + ); + + for (parent_bounty_id, old_child_bounty_id) in old_bounty_ids { + // assign new child bounty id let new_child_bounty_id = ParentTotalChildBounties::::get(parent_bounty_id); reads += 1; - ParentTotalChildBounties::::insert(parent_bounty_id, new_child_bounty_id.saturating_add(1)); + ParentTotalChildBounties::::insert( + parent_bounty_id, + new_child_bounty_id.saturating_add(1), + ); + writes += 1; + + let bounty_description = + v1::ChildBountyDescriptions::::take(old_child_bounty_id); writes += 1; - // should always be Some + let bounty_curator_fee = v1::ChildrenCuratorFees::::take(old_child_bounty_id); writes += 1; - if let Some(taken) = ChildBounties::::take(parent_bounty_id, old_child_bounty_id) { - writes += 1; + let child_bounty = ChildBounties::::take(parent_bounty_id, old_child_bounty_id); + writes += 1; + + // should always be some + if let Some(taken) = child_bounty { ChildBounties::::insert(parent_bounty_id, new_child_bounty_id, taken); + writes += 1; } if let Some(bounty_description) = bounty_description { + super::super::ChildBountyDescriptions::::insert( + parent_bounty_id, + new_child_bounty_id, + bounty_description, + ); writes += 1; - super::super::ChildBountyDescriptions::::insert(parent_bounty_id, new_child_bounty_id, bounty_description); } + super::super::ChildrenCuratorFees::::insert( + parent_bounty_id, + new_child_bounty_id, + bounty_curator_fee, + ); writes += 1; - super::super::ChildrenCuratorFees::::insert(parent_bounty_id, new_child_bounty_id, bounty_curator_fee); } + log::info!( + target: LOG_TARGET, + "Migration done, reads: {}, writes: {}", + reads, writes, + ); + T::DbWeight::get().reads_writes(reads, writes) } #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { - Ok(().encode()) + let old_child_bounty_count = ChildBounties::::iter_keys().count() as u32; + let old_child_bounty_descriptions = + v1::ChildBountyDescriptions::::iter_keys().count() as u32; + let old_child_bounty_curator_fee = + v1::ChildrenCuratorFees::::iter_keys().count() as u32; + Ok(( + old_child_bounty_count, + old_child_bounty_descriptions, + old_child_bounty_curator_fee, + ) + .encode()) } #[cfg(feature = "try-runtime")] fn post_upgrade(state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { + type StateType = (u32, u32, u32); + let ( + old_child_bounty_count, + old_child_bounty_descriptions, + old_child_bounty_curator_fee, + ): (u32, u32, u32) = StateType::decode(&mut &state[..]).expect("Can't decode previous state"); + let new_child_bounty_count = ChildBounties::::iter_keys().count() as u32; + let new_child_bounty_descriptions = + super::super::ChildBountyDescriptions::::iter_keys().count() as u32; + let new_child_bounty_curator_fee = + super::super::ChildrenCuratorFees::::iter_keys().count() as u32; + + ensure!( + old_child_bounty_count == new_child_bounty_count, + "child bounty count doesn't match" + ); + ensure!( + old_child_bounty_descriptions == new_child_bounty_descriptions, + "child bounty descriptions count doesn't match" + ); + ensure!( + old_child_bounty_curator_fee == new_child_bounty_curator_fee, + "child bounty curator fee count doesn't match" + ); + + ensure!( + v1::ChildBountyDescriptions::::iter_keys().count() == 0, + "child bounty descriptions should have been drained" + ); + ensure!( + v1::ChildrenCuratorFees::::iter_keys().count() == 0, + "child bounty curator fees should have been drained" + ); + Ok(()) } } @@ -71,4 +158,4 @@ pub type MigrateV0ToV1 = frame_support::migrations::VersionedMigration< v1::MigrateToV1Impl, Pallet, ::DbWeight, ->; \ No newline at end of file +>; From 2184af18d7c03acb03a9204886540dc9d5a49ea1 Mon Sep 17 00:00:00 2001 From: DavidK Date: Wed, 30 Oct 2024 11:39:13 +0200 Subject: [PATCH 04/36] log child bounty id remap --- .../frame/child-bounties/src/migration.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs index 69510db233bf6..8afa18ba35e83 100644 --- a/substrate/frame/child-bounties/src/migration.rs +++ b/substrate/frame/child-bounties/src/migration.rs @@ -57,6 +57,14 @@ pub mod v1 { ); writes += 1; + log::info!( + target: LOG_TARGET, + "Remapped parent bounty {} child bounty id {}->{}", + parent_bounty_id, + old_child_bounty_id, + new_child_bounty_id, + ); + let bounty_description = v1::ChildBountyDescriptions::::take(old_child_bounty_id); writes += 1; @@ -137,14 +145,8 @@ pub mod v1 { "child bounty curator fee count doesn't match" ); - ensure!( - v1::ChildBountyDescriptions::::iter_keys().count() == 0, - "child bounty descriptions should have been drained" - ); - ensure!( - v1::ChildrenCuratorFees::::iter_keys().count() == 0, - "child bounty curator fees should have been drained" - ); + log::info!("old child bounty descriptions: {}", v1::ChildBountyDescriptions::::iter_keys().count()); + log::info!("old child bounty curator fees descriptions: {}", v1::ChildrenCuratorFees::::iter_keys().count()); Ok(()) } From 39736393a1477aa3f0664ca4fe27febd2654804d Mon Sep 17 00:00:00 2001 From: DavidK Date: Wed, 30 Oct 2024 16:35:58 +0200 Subject: [PATCH 05/36] Restore rococo runtime version --- polkadot/runtime/rococo/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 6cc834e33a2e9..b82273833fd3a 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -171,7 +171,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("rococo"), impl_name: create_runtime_str!("parity-rococo-v2.0"), authoring_version: 0, - spec_version: 1_016_002, + spec_version: 1_016_001, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 26, From 4b0acea8a087d24209beecb72b0f4795c175b8da Mon Sep 17 00:00:00 2001 From: DavidK Date: Thu, 31 Oct 2024 11:04:48 +0200 Subject: [PATCH 06/36] Revert `ChildrenCuratorFees` changes --- Cargo.lock | 2 +- substrate/frame/child-bounties/src/lib.rs | 22 +++------- .../frame/child-bounties/src/migration.rs | 42 ++++--------------- substrate/frame/child-bounties/src/tests.rs | 2 +- 4 files changed, 16 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0956150e09a9b..30d2de1a89996 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16460,7 +16460,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b569754b15060d03000c09e3bf11509d527f60b75d79b4c30c3625b5071d9702" dependencies = [ "polkavm-derive-impl 0.14.0", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 846d4c9d152f7..6e7372e84fbb7 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -229,15 +229,8 @@ pub mod pallet { /// The cumulative child-bounty curator fee for each parent bounty. #[pallet::storage] - pub type ChildrenCuratorFees = StorageDoubleMap< - _, - Twox64Concat, - BountyIndex, - Twox64Concat, - BountyIndex, - BalanceOf, - ValueQuery, - >; + pub type ChildrenCuratorFees = + StorageMap<_, Twox64Concat, BountyIndex, BalanceOf, ValueQuery>; #[pallet::call] impl Pallet { @@ -373,7 +366,7 @@ pub mod pallet { // Add child-bounty curator fee to the cumulative sum. To be // subtracted from the parent bounty curator when claiming // bounty. - ChildrenCuratorFees::::mutate(parent_bounty_id, child_bounty_id, |value| { + ChildrenCuratorFees::::mutate(parent_bounty_id, |value| { *value = value.saturating_add(fee) }); @@ -887,7 +880,7 @@ impl Pallet { // Revert the curator fee back to parent bounty curator & // reduce the active child-bounty count. - ChildrenCuratorFees::::mutate(parent_bounty_id, child_bounty_id, |value| { + ChildrenCuratorFees::::mutate(parent_bounty_id, |value| { *value = value.saturating_sub(child_bounty.fee) }); ParentChildBounties::::mutate(parent_bounty_id, |count| { @@ -935,11 +928,8 @@ impl pallet_bounties::ChildBountyManager> for Pallet fn children_curator_fees(bounty_id: pallet_bounties::BountyIndex) -> BalanceOf { // This is asked for when the parent bounty is being claimed. No use of // keeping it in state after that. Hence removing. - let mut children_fee_total = 0u32.into(); - for child_fee in ChildrenCuratorFees::::iter_prefix_values(bounty_id) { - children_fee_total += child_fee; - } - ChildrenCuratorFees::::drain_prefix(bounty_id); + let children_fee_total = ChildrenCuratorFees::::get(bounty_id); + ChildrenCuratorFees::::remove(bounty_id); children_fee_total } } diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs index 8afa18ba35e83..dbc9dd023e8ca 100644 --- a/substrate/frame/child-bounties/src/migration.rs +++ b/substrate/frame/child-bounties/src/migration.rs @@ -24,10 +24,6 @@ pub mod v1 { BoundedVec::MaximumReasonLength>, >; - #[storage_alias] - type ChildrenCuratorFees = - StorageMap, Twox64Concat, BountyIndex, BalanceOf, ValueQuery>; - impl UncheckedOnRuntimeUpgrade for MigrateToV1Impl { fn on_runtime_upgrade() -> frame_support::weights::Weight { // increment reads/writes after the action @@ -68,8 +64,6 @@ pub mod v1 { let bounty_description = v1::ChildBountyDescriptions::::take(old_child_bounty_id); writes += 1; - let bounty_curator_fee = v1::ChildrenCuratorFees::::take(old_child_bounty_id); - writes += 1; let child_bounty = ChildBounties::::take(parent_bounty_id, old_child_bounty_id); writes += 1; @@ -86,12 +80,6 @@ pub mod v1 { ); writes += 1; } - super::super::ChildrenCuratorFees::::insert( - parent_bounty_id, - new_child_bounty_id, - bounty_curator_fee, - ); - writes += 1; } log::info!( @@ -108,29 +96,17 @@ pub mod v1 { let old_child_bounty_count = ChildBounties::::iter_keys().count() as u32; let old_child_bounty_descriptions = v1::ChildBountyDescriptions::::iter_keys().count() as u32; - let old_child_bounty_curator_fee = - v1::ChildrenCuratorFees::::iter_keys().count() as u32; - Ok(( - old_child_bounty_count, - old_child_bounty_descriptions, - old_child_bounty_curator_fee, - ) - .encode()) + Ok((old_child_bounty_count, old_child_bounty_descriptions).encode()) } #[cfg(feature = "try-runtime")] fn post_upgrade(state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { - type StateType = (u32, u32, u32); - let ( - old_child_bounty_count, - old_child_bounty_descriptions, - old_child_bounty_curator_fee, - ): (u32, u32, u32) = StateType::decode(&mut &state[..]).expect("Can't decode previous state"); + type StateType = (u32, u32); + let (old_child_bounty_count, old_child_bounty_descriptions) = + StateType::decode(&mut &state[..]).expect("Can't decode previous state"); let new_child_bounty_count = ChildBounties::::iter_keys().count() as u32; let new_child_bounty_descriptions = super::super::ChildBountyDescriptions::::iter_keys().count() as u32; - let new_child_bounty_curator_fee = - super::super::ChildrenCuratorFees::::iter_keys().count() as u32; ensure!( old_child_bounty_count == new_child_bounty_count, @@ -140,13 +116,11 @@ pub mod v1 { old_child_bounty_descriptions == new_child_bounty_descriptions, "child bounty descriptions count doesn't match" ); - ensure!( - old_child_bounty_curator_fee == new_child_bounty_curator_fee, - "child bounty curator fee count doesn't match" - ); - log::info!("old child bounty descriptions: {}", v1::ChildBountyDescriptions::::iter_keys().count()); - log::info!("old child bounty curator fees descriptions: {}", v1::ChildrenCuratorFees::::iter_keys().count()); + log::info!( + "old child bounty descriptions: {}", + v1::ChildBountyDescriptions::::iter_keys().count() + ); Ok(()) } diff --git a/substrate/frame/child-bounties/src/tests.rs b/substrate/frame/child-bounties/src/tests.rs index c0948402ee058..c222df00eeee1 100644 --- a/substrate/frame/child-bounties/src/tests.rs +++ b/substrate/frame/child-bounties/src/tests.rs @@ -1222,7 +1222,7 @@ fn children_curator_fee_calculation_test() { // Propose curator for child-bounty. assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee)); // Check curator fee added to the sum. - assert_eq!(pallet_child_bounties::ChildrenCuratorFees::::get(0, 0), fee); + assert_eq!(pallet_child_bounties::ChildrenCuratorFees::::get(0), fee); // Accept curator for child-bounty. assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0)); // Award child-bounty. From 5bb6ff441d2743c246ee347e39f36995a50fe3bb Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 4 Nov 2024 10:31:51 +0200 Subject: [PATCH 07/36] Add license to migration --- .../frame/child-bounties/src/migration.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs index dbc9dd023e8ca..9cb0d07e73341 100644 --- a/substrate/frame/child-bounties/src/migration.rs +++ b/substrate/frame/child-bounties/src/migration.rs @@ -1,5 +1,21 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + use super::*; -// use codec::{Decode, Encode}; use core::marker::PhantomData; use frame_support::{ storage_alias, From 6df9727df07d982c391eb18b0515f1f726a9e85c Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 4 Nov 2024 10:47:03 +0200 Subject: [PATCH 08/36] Add licence and prdoc --- prdoc/pr_6255.prdoc | 14 ++++++++++++++ substrate/frame/child-bounties/src/lib.rs | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 prdoc/pr_6255.prdoc diff --git a/prdoc/pr_6255.prdoc b/prdoc/pr_6255.prdoc new file mode 100644 index 0000000000000..db01ca625c222 --- /dev/null +++ b/prdoc/pr_6255.prdoc @@ -0,0 +1,14 @@ +title: '[pallet-child-bounties] Index child bounties by parent bounty' +doc: +- audience: Runtime Dev + description: | + Indexes child bounties by parent bounty. This allows to quickly + list child bounties and their descriptions from the parent bounty + by changing `ChildBountyDescriptions` to use `StorageDoubleMap` + which is indexed by `(ParentBounty, ChildBounty)` keys. + + Migration is provided to migrate `ChildBountyDescriptions` and + `ChildBounties` storage items. +crates: +- name: pallet-child-bounties + bump: major diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 6e7372e84fbb7..126fa3c734b9a 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -190,7 +190,7 @@ pub mod pallet { } /// DEPRECATED: Replaced with `ParentTotalChildBounties` storage item keeping dedicated counts - /// for each parent bounty. Number of total child bounties. + /// for each parent bounty. Number of total child bounties. Will be removed in May 2025. #[pallet::storage] pub type ChildBountyCount = StorageValue<_, BountyIndex, ValueQuery>; From 7601baff46faf0734ce3c3c8b04729a63fb09390 Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 4 Nov 2024 10:48:30 +0200 Subject: [PATCH 09/36] Add deprecation date in prdoc --- prdoc/pr_6255.prdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prdoc/pr_6255.prdoc b/prdoc/pr_6255.prdoc index db01ca625c222..79511c77fe246 100644 --- a/prdoc/pr_6255.prdoc +++ b/prdoc/pr_6255.prdoc @@ -7,6 +7,8 @@ doc: by changing `ChildBountyDescriptions` to use `StorageDoubleMap` which is indexed by `(ParentBounty, ChildBounty)` keys. + Deprecates `ChildBountyCount` storage item in May 2025. + Migration is provided to migrate `ChildBountyDescriptions` and `ChildBounties` storage items. crates: From fb006da7ae338d65d9ae0f0318012061aaa18061 Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 4 Nov 2024 10:57:22 +0200 Subject: [PATCH 10/36] Remove v1:: prefix --- substrate/frame/child-bounties/src/migration.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs index 9cb0d07e73341..350c63777c037 100644 --- a/substrate/frame/child-bounties/src/migration.rs +++ b/substrate/frame/child-bounties/src/migration.rs @@ -77,8 +77,7 @@ pub mod v1 { new_child_bounty_id, ); - let bounty_description = - v1::ChildBountyDescriptions::::take(old_child_bounty_id); + let bounty_description = ChildBountyDescriptions::::take(old_child_bounty_id); writes += 1; let child_bounty = ChildBounties::::take(parent_bounty_id, old_child_bounty_id); writes += 1; From 6494780143dccde677d1d489691cd530bff71526 Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 4 Nov 2024 11:12:06 +0200 Subject: [PATCH 11/36] Document more functions for ChildBountyManager --- substrate/frame/child-bounties/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 126fa3c734b9a..451008262a922 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -919,12 +919,15 @@ impl Pallet { // where we pass the active child bounties and child curator fees to the parent // bounty. impl pallet_bounties::ChildBountyManager> for Pallet { + /// Returns number of active child bounties for `bounty_id` fn child_bounties_count( bounty_id: pallet_bounties::BountyIndex, ) -> pallet_bounties::BountyIndex { ParentChildBounties::::get(bounty_id) } + /// Returns cumulative child bounty curator fees for `bounty_id` also removing the associated + /// storage item. This function is assumed to be called when parent bounty is claimed. fn children_curator_fees(bounty_id: pallet_bounties::BountyIndex) -> BalanceOf { // This is asked for when the parent bounty is being claimed. No use of // keeping it in state after that. Hence removing. From 8fcfdb2aeed7f7049d39ed4afdd6f899ad152ce9 Mon Sep 17 00:00:00 2001 From: DavidK Date: Mon, 4 Nov 2024 12:51:53 +0200 Subject: [PATCH 12/36] Add sorting for ids to preserve order --- substrate/frame/child-bounties/src/migration.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs index 350c63777c037..83f5a6178487d 100644 --- a/substrate/frame/child-bounties/src/migration.rs +++ b/substrate/frame/child-bounties/src/migration.rs @@ -53,6 +53,9 @@ pub mod v1 { old_bounty_ids.push((parent_bounty_id, old_child_bounty_id)); } + // keep ids order roughly the same with the old order + old_bounty_ids.sort(); + log::info!( target: LOG_TARGET, "Migrating {} child bounties", From 4613794b53b95ac33eb4a7a2521325b11fcafb0b Mon Sep 17 00:00:00 2001 From: DavidK Date: Tue, 5 Nov 2024 10:02:24 +0200 Subject: [PATCH 13/36] Add transfer weights - additional logging fixes - move child bounty account id balances - modify derived address for child bounty account --- polkadot/runtime/rococo/src/lib.rs | 3 +- substrate/frame/child-bounties/src/lib.rs | 27 +++-- .../frame/child-bounties/src/migration.rs | 101 ++++++++++++++---- substrate/frame/child-bounties/src/tests.rs | 26 ++--- 4 files changed, 114 insertions(+), 43 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index f23d7040edbc8..a6e7bd025da06 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1661,6 +1661,7 @@ pub mod migrations { pub const PhragmenElectionPalletId: LockIdentifier = *b"phrelect"; /// Weight for balance unreservations pub BalanceUnreserveWeight: Weight = weights::pallet_balances_balances::WeightInfo::::force_unreserve(); + pub BalanceTransferAllowDeath: Weight = weights::pallet_balances_balances::WeightInfo::::transfer_allow_death(); } // Special Config for Gov V1 pallets, allowing us to run migrations for them without @@ -1710,7 +1711,7 @@ pub mod migrations { paras_registrar::migration::MigrateToV1, pallet_referenda::migration::v1::MigrateV0ToV1, pallet_referenda::migration::v1::MigrateV0ToV1, - pallet_child_bounties::migration::MigrateV0ToV1, + pallet_child_bounties::migration::MigrateV0ToV1, // Unlock & unreserve Gov1 funds diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 3f6e399c3111e..57117f22f08f1 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -221,7 +221,7 @@ pub mod pallet { /// The description of each child-bounty. #[pallet::storage] - pub type ChildBountyDescriptions = StorageDoubleMap< + pub type ParentChildBountyDescriptions = StorageDoubleMap< _, Twox64Concat, BountyIndex, @@ -297,7 +297,8 @@ pub mod pallet { // Get child-bounty ID. let child_bounty_id = ParentTotalChildBounties::::get(parent_bounty_id); - let child_bounty_account = Self::child_bounty_account_id(child_bounty_id); + let child_bounty_account = + Self::child_bounty_account_id(parent_bounty_id, child_bounty_id); // Transfer funds from parent bounty to child-bounty. T::Currency::transfer(&parent_bounty_account, &child_bounty_account, value, KeepAlive)?; @@ -695,7 +696,8 @@ pub mod pallet { ); // Make curator fee payment. - let child_bounty_account = Self::child_bounty_account_id(child_bounty_id); + let child_bounty_account = + Self::child_bounty_account_id(parent_bounty_id, child_bounty_id); let balance = T::Currency::free_balance(&child_bounty_account); let curator_fee = child_bounty.fee.min(balance); let payout = balance.saturating_sub(curator_fee); @@ -739,7 +741,10 @@ pub mod pallet { }); // Remove the child-bounty description. - ChildBountyDescriptions::::remove(parent_bounty_id, child_bounty_id); + ParentChildBountyDescriptions::::remove( + parent_bounty_id, + child_bounty_id, + ); // Remove the child-bounty instance from the state. *maybe_child_bounty = None; @@ -820,11 +825,14 @@ impl Pallet { } /// The account ID of a child-bounty account. - pub fn child_bounty_account_id(id: BountyIndex) -> T::AccountId { + pub fn child_bounty_account_id( + parent_bounty_id: BountyIndex, + child_bounty_id: BountyIndex, + ) -> T::AccountId { // This function is taken from the parent (bounties) pallet, but the // prefix is changed to have different AccountId when the index of // parent and child is same. - T::PalletId::get().into_sub_account_truncating(("cb", id)) + T::PalletId::get().into_sub_account_truncating(("cb", parent_bounty_id, child_bounty_id)) } fn create_child_bounty( @@ -841,7 +849,7 @@ impl Pallet { status: ChildBountyStatus::Added, }; ChildBounties::::insert(parent_bounty_id, child_bounty_id, &child_bounty); - ChildBountyDescriptions::::insert(parent_bounty_id, child_bounty_id, description); + ParentChildBountyDescriptions::::insert(parent_bounty_id, child_bounty_id, description); Self::deposit_event(Event::Added { index: parent_bounty_id, child_index: child_bounty_id }); } @@ -900,7 +908,8 @@ impl Pallet { // Transfer fund from child-bounty to parent bounty. let parent_bounty_account = pallet_bounties::Pallet::::bounty_account_id(parent_bounty_id); - let child_bounty_account = Self::child_bounty_account_id(child_bounty_id); + let child_bounty_account = + Self::child_bounty_account_id(parent_bounty_id, child_bounty_id); let balance = T::Currency::free_balance(&child_bounty_account); let transfer_result = T::Currency::transfer( &child_bounty_account, @@ -911,7 +920,7 @@ impl Pallet { debug_assert!(transfer_result.is_ok()); // Remove the child-bounty description. - ChildBountyDescriptions::::remove(parent_bounty_id, child_bounty_id); + ParentChildBountyDescriptions::::remove(parent_bounty_id, child_bounty_id); *maybe_child_bounty = None; diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs index 83f5a6178487d..166483b89f35b 100644 --- a/substrate/frame/child-bounties/src/migration.rs +++ b/substrate/frame/child-bounties/src/migration.rs @@ -22,6 +22,7 @@ use frame_support::{ traits::{Get, UncheckedOnRuntimeUpgrade}, }; +use alloc::collections::BTreeSet; #[cfg(feature = "try-runtime")] use alloc::vec::Vec; #[cfg(feature = "try-runtime")] @@ -30,7 +31,7 @@ use frame_support::ensure; pub mod v1 { use super::*; - pub struct MigrateToV1Impl(PhantomData); + pub struct MigrateToV1Impl(PhantomData<(T, TransferWeight)>); #[storage_alias] type ChildBountyDescriptions = StorageMap< @@ -40,22 +41,23 @@ pub mod v1 { BoundedVec::MaximumReasonLength>, >; - impl UncheckedOnRuntimeUpgrade for MigrateToV1Impl { + impl> UncheckedOnRuntimeUpgrade + for MigrateToV1Impl + { fn on_runtime_upgrade() -> frame_support::weights::Weight { // increment reads/writes after the action let mut reads = 0u64; let mut writes = 0u64; + let mut transfer_weights: Weight = Weight::zero(); - let mut old_bounty_ids = Vec::new(); + // keep ids order roughly the same with the old order + let mut old_bounty_ids = BTreeSet::new(); // first iteration collect all existing ids not to mutate map as we iterate it for (parent_bounty_id, old_child_bounty_id) in ChildBounties::::iter_keys() { reads += 1; - old_bounty_ids.push((parent_bounty_id, old_child_bounty_id)); + old_bounty_ids.insert((parent_bounty_id, old_child_bounty_id)); } - // keep ids order roughly the same with the old order - old_bounty_ids.sort(); - log::info!( target: LOG_TARGET, "Migrating {} child bounties", @@ -72,6 +74,29 @@ pub mod v1 { ); writes += 1; + let old_child_bounty_account = + Self::old_child_bounty_account_id(old_child_bounty_id); + let new_child_bounty_account = + Pallet::::child_bounty_account_id(parent_bounty_id, new_child_bounty_id); + let old_balance = T::Currency::free_balance(&old_child_bounty_account); + log::info!( + "Transferring {:?} funds from old child bounty account {:?} to new child bounty account {:?}", + old_balance, old_child_bounty_account, new_child_bounty_account + ); + if let Err(err) = T::Currency::transfer( + &old_child_bounty_account, + &new_child_bounty_account, + old_balance, + AllowDeath, + ) { + log::error!( + target: LOG_TARGET, + "Error transferring funds: {:?}", + err + ); + } + transfer_weights += TransferWeight::get(); + log::info!( target: LOG_TARGET, "Remapped parent bounty {} child bounty id {}->{}", @@ -89,24 +114,34 @@ pub mod v1 { if let Some(taken) = child_bounty { ChildBounties::::insert(parent_bounty_id, new_child_bounty_id, taken); writes += 1; + } else { + log::error!( + "child bounty with old id {} not found, should be impossible", + old_child_bounty_id + ); } if let Some(bounty_description) = bounty_description { - super::super::ChildBountyDescriptions::::insert( + super::super::ParentChildBountyDescriptions::::insert( parent_bounty_id, new_child_bounty_id, bounty_description, ); writes += 1; + } else { + log::error!( + "child bounty description with old id {} not found, should be impossible", + old_child_bounty_id + ); } } log::info!( target: LOG_TARGET, - "Migration done, reads: {}, writes: {}", - reads, writes, + "Migration done, reads: {}, writes: {}, transfer weights: {}", + reads, writes, transfer_weights ); - T::DbWeight::get().reads_writes(reads, writes) + T::DbWeight::get().reads_writes(reads, writes) + transfer_weights } #[cfg(feature = "try-runtime")] @@ -114,17 +149,19 @@ pub mod v1 { let old_child_bounty_count = ChildBounties::::iter_keys().count() as u32; let old_child_bounty_descriptions = v1::ChildBountyDescriptions::::iter_keys().count() as u32; - Ok((old_child_bounty_count, old_child_bounty_descriptions).encode()) + let old_child_bounty_ids = ChildBounties::::iter_keys().collect::>(); + Ok((old_child_bounty_count, old_child_bounty_descriptions, old_child_bounty_ids) + .encode()) } #[cfg(feature = "try-runtime")] fn post_upgrade(state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { - type StateType = (u32, u32); - let (old_child_bounty_count, old_child_bounty_descriptions) = + type StateType = (u32, u32, Vec<(u32, u32)>); + let (old_child_bounty_count, old_child_bounty_descriptions, old_child_bounty_ids) = StateType::decode(&mut &state[..]).expect("Can't decode previous state"); let new_child_bounty_count = ChildBounties::::iter_keys().count() as u32; let new_child_bounty_descriptions = - super::super::ChildBountyDescriptions::::iter_keys().count() as u32; + super::super::ParentChildBountyDescriptions::::iter_keys().count() as u32; ensure!( old_child_bounty_count == new_child_bounty_count, @@ -135,21 +172,45 @@ pub mod v1 { "child bounty descriptions count doesn't match" ); - log::info!( - "old child bounty descriptions: {}", - v1::ChildBountyDescriptions::::iter_keys().count() + let old_child_bounty_descriptions_storage = + v1::ChildBountyDescriptions::::iter_keys().count(); + log::info!("old child bounty descriptions: {}", old_child_bounty_descriptions_storage); + ensure!( + old_child_bounty_descriptions_storage == 0, + "Old bounty descriptions should have been drained." ); + for (_, old_child_bounty_id) in old_child_bounty_ids { + let old_account_id = Self::old_child_bounty_account_id(old_child_bounty_id); + let balance = T::Currency::total_balance(&old_account_id); + if !balance.is_zero() { + log::error!( + "Old child bounty id {} still has balance {:?}", + old_child_bounty_id, + balance + ); + } + } + Ok(()) } } + + impl> MigrateToV1Impl { + fn old_child_bounty_account_id(id: BountyIndex) -> T::AccountId { + // This function is taken from the parent (bounties) pallet, but the + // prefix is changed to have different AccountId when the index of + // parent and child is same. + T::PalletId::get().into_sub_account_truncating(("cb", id)) + } + } } /// Migrate the pallet storage from `0` to `1`. -pub type MigrateV0ToV1 = frame_support::migrations::VersionedMigration< +pub type MigrateV0ToV1 = frame_support::migrations::VersionedMigration< 0, 1, - v1::MigrateToV1Impl, + v1::MigrateToV1Impl, Pallet, ::DbWeight, >; diff --git a/substrate/frame/child-bounties/src/tests.rs b/substrate/frame/child-bounties/src/tests.rs index 69ebcdd34f65d..61054ed8763fe 100644 --- a/substrate/frame/child-bounties/src/tests.rs +++ b/substrate/frame/child-bounties/src/tests.rs @@ -269,7 +269,7 @@ fn add_child_bounty() { // Check the child-bounty description status. assert_eq!( - pallet_child_bounties::ChildBountyDescriptions::::get(0, 0).unwrap(), + pallet_child_bounties::ParentChildBountyDescriptions::::get(0, 0).unwrap(), b"12345-p1".to_vec(), ); }); @@ -325,8 +325,8 @@ fn child_bounty_assign_curator() { assert_eq!(Balances::reserved_balance(Bounties::bounty_account_id(0)), 0); // Child-bounty account status. - assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0)), 10); - assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0)), 0); + assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0, 0)), 10); + assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0, 0)), 0); let fee = 6u64; assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee)); @@ -375,8 +375,8 @@ fn child_bounty_assign_curator() { assert_eq!(Balances::reserved_balance(Bounties::bounty_account_id(0)), 0); // Child-bounty account status at exit. - assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0)), 10); - assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0)), 0); + assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0, 0)), 10); + assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0, 0)), 0); // Treasury account status at exit. assert_eq!(Balances::free_balance(Treasury::account_id()), 26); @@ -466,8 +466,8 @@ fn award_claim_child_bounty() { assert_eq!(Balances::reserved_balance(7), 0); // Child-bounty account status. - assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0)), 0); - assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0)), 0); + assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0, 0)), 0); + assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0, 0)), 0); // Check the child-bounty count. assert_eq!(pallet_child_bounties::ParentChildBounties::::get(0), 0); @@ -525,8 +525,8 @@ fn close_child_bounty_added() { assert_eq!(Balances::reserved_balance(Bounties::bounty_account_id(0)), 0); // Child-bounty account status. - assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0)), 0); - assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0)), 0); + assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0, 0)), 0); + assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0, 0)), 0); }); } @@ -582,8 +582,8 @@ fn close_child_bounty_active() { assert_eq!(Balances::reserved_balance(Bounties::bounty_account_id(0)), 0); // Child-bounty account status. - assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0)), 0); - assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0)), 0); + assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0, 0)), 0); + assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0, 0)), 0); }); } @@ -642,8 +642,8 @@ fn close_child_bounty_pending() { assert_eq!(Balances::free_balance(8), 101 - expected_child_deposit); // Child-bounty account status. - assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0)), 10); - assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0)), 0); + assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0, 0)), 10); + assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0, 0)), 0); }); } From 78ac085280d635bb9032aac0aa852b6f62961434 Mon Sep 17 00:00:00 2001 From: DavidK Date: Tue, 5 Nov 2024 12:03:58 +0200 Subject: [PATCH 14/36] Keep old deprecated ChildBountyDescriptions storage item --- substrate/frame/child-bounties/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 57117f22f08f1..e458b588ba7ab 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -219,6 +219,12 @@ pub mod pallet { ChildBounty, BlockNumberFor>, >; + /// DEPRECATED: Old map of child bounty descriptions which uses deprecated ChildBountyCount for + /// keys, to be removed in May 2025 + #[pallet::storage] + pub type ChildBountyDescriptions = + StorageMap<_, Twox64Concat, BountyIndex, BoundedVec>; + /// The description of each child-bounty. #[pallet::storage] pub type ParentChildBountyDescriptions = StorageDoubleMap< From b70fa93e758b682f74942e60ff4a993a09726a0c Mon Sep 17 00:00:00 2001 From: DavidK Date: Tue, 5 Nov 2024 12:13:26 +0200 Subject: [PATCH 15/36] Update Cargo.lock file --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b7dffe3614a6..53a521b58214c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3100,7 +3100,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] @@ -16838,7 +16838,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2 1.0.86", "quote 1.0.37", - "syn 2.0.82", + "syn 2.0.85", ] [[package]] From 6700f25c963902e943e8247bf064dcb89d7521f3 Mon Sep 17 00:00:00 2001 From: DavidK Date: Tue, 5 Nov 2024 12:20:51 +0200 Subject: [PATCH 16/36] Add old to new child bounty ids mapping --- substrate/frame/child-bounties/src/lib.rs | 6 ++++++ substrate/frame/child-bounties/src/migration.rs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index e458b588ba7ab..ccfe157487265 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -236,6 +236,12 @@ pub mod pallet { BoundedVec, >; + /// Stores a mapping of `old_child_bounty_id` generated from deprecated `ChildBountyCount` + /// storage item to new pair of parent/child ids (`parent_bounty_id`, `new_child_bounty_id`) + #[pallet::storage] + pub type OldToNewChildBountyIds = + StorageMap<_, Twox64Concat, BountyIndex, (BountyIndex, BountyIndex)>; + /// The cumulative child-bounty curator fee for each parent bounty. #[pallet::storage] pub type ChildrenCuratorFees = diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs index 166483b89f35b..5d5ee4dec1573 100644 --- a/substrate/frame/child-bounties/src/migration.rs +++ b/substrate/frame/child-bounties/src/migration.rs @@ -74,6 +74,12 @@ pub mod v1 { ); writes += 1; + OldToNewChildBountyIds::::insert( + old_child_bounty_id, + (parent_bounty_id, new_child_bounty_id), + ); + writes += 1; + let old_child_bounty_account = Self::old_child_bounty_account_id(old_child_bounty_id); let new_child_bounty_account = From 4c29a2fc236de2a7e4ddb5bd0e6c4761e72e18b3 Mon Sep 17 00:00:00 2001 From: DavidK Date: Tue, 5 Nov 2024 12:34:44 +0200 Subject: [PATCH 17/36] Update docs --- substrate/frame/child-bounties/src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index ccfe157487265..3f7af6c5a25ea 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -946,9 +946,12 @@ impl Pallet { } } -// Implement ChildBountyManager to connect with the bounties pallet. This is -// where we pass the active child bounties and child curator fees to the parent -// bounty. +/// Implement ChildBountyManager to connect with the bounties pallet. This is +/// where we pass the active child bounties and child curator fees to the parent +/// bounty. +/// +/// Function `children_curator_fees` not only returns the fee but also removes cumulative curator +/// fees during call. impl pallet_bounties::ChildBountyManager> for Pallet { /// Returns number of active child bounties for `bounty_id` fn child_bounties_count( From d30c3cfc3f925ff3c1083f67a5260936669d2022 Mon Sep 17 00:00:00 2001 From: DavidK Date: Tue, 5 Nov 2024 12:41:27 +0200 Subject: [PATCH 18/36] Add prdoc about old to new ids storage item --- prdoc/pr_6255.prdoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/prdoc/pr_6255.prdoc b/prdoc/pr_6255.prdoc index 79511c77fe246..e625564476c82 100644 --- a/prdoc/pr_6255.prdoc +++ b/prdoc/pr_6255.prdoc @@ -11,6 +11,9 @@ doc: Migration is provided to migrate `ChildBountyDescriptions` and `ChildBounties` storage items. + + Old pre-migration ids mapping is stored in the `OldToNewChildBountyIds` + storage item. crates: - name: pallet-child-bounties bump: major From 38ae98157e8ead313006dcdc3cbcf40f34e3b3b8 Mon Sep 17 00:00:00 2001 From: DavidK Date: Tue, 5 Nov 2024 13:31:23 +0200 Subject: [PATCH 19/36] Rename ParentChildBountyDescriptions to ChildBountyDescriptionsV2 --- substrate/frame/child-bounties/src/lib.rs | 11 ++++------- substrate/frame/child-bounties/src/migration.rs | 4 ++-- substrate/frame/child-bounties/src/tests.rs | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 3f7af6c5a25ea..6f53a82f6f8a8 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -227,7 +227,7 @@ pub mod pallet { /// The description of each child-bounty. #[pallet::storage] - pub type ParentChildBountyDescriptions = StorageDoubleMap< + pub type ChildBountyDescriptionsV2 = StorageDoubleMap< _, Twox64Concat, BountyIndex, @@ -753,10 +753,7 @@ pub mod pallet { }); // Remove the child-bounty description. - ParentChildBountyDescriptions::::remove( - parent_bounty_id, - child_bounty_id, - ); + ChildBountyDescriptionsV2::::remove(parent_bounty_id, child_bounty_id); // Remove the child-bounty instance from the state. *maybe_child_bounty = None; @@ -861,7 +858,7 @@ impl Pallet { status: ChildBountyStatus::Added, }; ChildBounties::::insert(parent_bounty_id, child_bounty_id, &child_bounty); - ParentChildBountyDescriptions::::insert(parent_bounty_id, child_bounty_id, description); + ChildBountyDescriptionsV2::::insert(parent_bounty_id, child_bounty_id, description); Self::deposit_event(Event::Added { index: parent_bounty_id, child_index: child_bounty_id }); } @@ -932,7 +929,7 @@ impl Pallet { debug_assert!(transfer_result.is_ok()); // Remove the child-bounty description. - ParentChildBountyDescriptions::::remove(parent_bounty_id, child_bounty_id); + ChildBountyDescriptionsV2::::remove(parent_bounty_id, child_bounty_id); *maybe_child_bounty = None; diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs index 5d5ee4dec1573..4f21ada924510 100644 --- a/substrate/frame/child-bounties/src/migration.rs +++ b/substrate/frame/child-bounties/src/migration.rs @@ -127,7 +127,7 @@ pub mod v1 { ); } if let Some(bounty_description) = bounty_description { - super::super::ParentChildBountyDescriptions::::insert( + super::super::ChildBountyDescriptionsV2::::insert( parent_bounty_id, new_child_bounty_id, bounty_description, @@ -167,7 +167,7 @@ pub mod v1 { StateType::decode(&mut &state[..]).expect("Can't decode previous state"); let new_child_bounty_count = ChildBounties::::iter_keys().count() as u32; let new_child_bounty_descriptions = - super::super::ParentChildBountyDescriptions::::iter_keys().count() as u32; + super::super::ChildBountyDescriptionsV2::::iter_keys().count() as u32; ensure!( old_child_bounty_count == new_child_bounty_count, diff --git a/substrate/frame/child-bounties/src/tests.rs b/substrate/frame/child-bounties/src/tests.rs index 61054ed8763fe..032685163ef73 100644 --- a/substrate/frame/child-bounties/src/tests.rs +++ b/substrate/frame/child-bounties/src/tests.rs @@ -269,7 +269,7 @@ fn add_child_bounty() { // Check the child-bounty description status. assert_eq!( - pallet_child_bounties::ParentChildBountyDescriptions::::get(0, 0).unwrap(), + pallet_child_bounties::ChildBountyDescriptionsV2::::get(0, 0).unwrap(), b"12345-p1".to_vec(), ); }); From 84ad94c02fa7d545bd941ecd82cecb7f2885ed2f Mon Sep 17 00:00:00 2001 From: DavidK Date: Tue, 5 Nov 2024 14:48:32 +0200 Subject: [PATCH 20/36] Prdoc changes --- prdoc/pr_6255.prdoc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/prdoc/pr_6255.prdoc b/prdoc/pr_6255.prdoc index e625564476c82..0042e5b77e282 100644 --- a/prdoc/pr_6255.prdoc +++ b/prdoc/pr_6255.prdoc @@ -7,12 +7,11 @@ doc: by changing `ChildBountyDescriptions` to use `StorageDoubleMap` which is indexed by `(ParentBounty, ChildBounty)` keys. - Deprecates `ChildBountyCount` storage item in May 2025. - - Migration is provided to migrate `ChildBountyDescriptions` and + - Changes child bounty keys in `ChildBounties` storage item. + - Deprecates `ChildBountyCount` storage item in May 2025. + - Migration is provided to migrate `ChildBountyDescriptions` and `ChildBounties` storage items. - - Old pre-migration ids mapping is stored in the `OldToNewChildBountyIds` + - Old pre-migration ids mapping is stored in the `OldToNewChildBountyIds` storage item. crates: - name: pallet-child-bounties From 9efd09d0b2b555dd6d98746bac5217e0955b2c92 Mon Sep 17 00:00:00 2001 From: DavidK Date: Tue, 5 Nov 2024 14:49:03 +0200 Subject: [PATCH 21/36] Add migration docs --- substrate/frame/child-bounties/src/lib.rs | 6 ------ substrate/frame/child-bounties/src/migration.rs | 7 +++++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 6f53a82f6f8a8..87f80bfe7ca7d 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -219,12 +219,6 @@ pub mod pallet { ChildBounty, BlockNumberFor>, >; - /// DEPRECATED: Old map of child bounty descriptions which uses deprecated ChildBountyCount for - /// keys, to be removed in May 2025 - #[pallet::storage] - pub type ChildBountyDescriptions = - StorageMap<_, Twox64Concat, BountyIndex, BoundedVec>; - /// The description of each child-bounty. #[pallet::storage] pub type ChildBountyDescriptionsV2 = StorageDoubleMap< diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs index 4f21ada924510..4fd8d7b2d9e8c 100644 --- a/substrate/frame/child-bounties/src/migration.rs +++ b/substrate/frame/child-bounties/src/migration.rs @@ -31,6 +31,13 @@ use frame_support::ensure; pub mod v1 { use super::*; + /// Migration to index `ChildBountyDescriptions` by parent bounty in a `StorageDoubleMap`. + /// Reassigns new ids for child bounties composed of `(parent_bounty_id, child_bounty_id)`. + /// Creates a map of `OldToNewChildBountyIds` to find new child bounty id from old child bounty + /// id. + /// + /// `TransferWeight` returns `Weight` of `unreserve_balance` operation which is perfomed during + /// this migration. pub struct MigrateToV1Impl(PhantomData<(T, TransferWeight)>); #[storage_alias] From 7cab4cee2955448ccaba8fd639fed60c7cffead1 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 5 Nov 2024 15:49:56 +0100 Subject: [PATCH 22/36] add bounty removed hook --- substrate/frame/bounties/src/lib.rs | 22 +++++++++++++------- substrate/frame/child-bounties/src/lib.rs | 23 ++++++++++++++------- substrate/frame/child-bounties/src/tests.rs | 10 +++++++++ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/substrate/frame/bounties/src/lib.rs b/substrate/frame/bounties/src/lib.rs index 6e0bfa6084e1a..1a8b4d79fa102 100644 --- a/substrate/frame/bounties/src/lib.rs +++ b/substrate/frame/bounties/src/lib.rs @@ -188,8 +188,11 @@ pub trait ChildBountyManager { /// Get the active child bounties for a parent bounty. fn child_bounties_count(bounty_id: BountyIndex) -> BountyIndex; - /// Get total curator fees of children-bounty curators. + /// Take total curator fees of children-bounty curators. fn children_curator_fees(bounty_id: BountyIndex) -> Balance; + + /// Hook called when a parent bounty is removed. + fn bounty_removed(bounty_id: BountyIndex); } #[frame_support::pallet] @@ -466,12 +469,12 @@ pub mod pallet { Bounties::::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult { let bounty = maybe_bounty.as_mut().ok_or(Error::::InvalidIndex)?; - let slash_curator = - |curator: &T::AccountId, curator_deposit: &mut BalanceOf| { - let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; - T::OnSlash::on_unbalanced(imbalance); - *curator_deposit = Zero::zero(); - }; + let slash_curator = |curator: &T::AccountId, + curator_deposit: &mut BalanceOf| { + let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; + T::OnSlash::on_unbalanced(imbalance); + *curator_deposit = Zero::zero(); + }; match bounty.status { BountyStatus::Proposed | BountyStatus::Approved | BountyStatus::Funded => { @@ -678,6 +681,7 @@ pub mod pallet { *maybe_bounty = None; BountyDescriptions::::remove(bounty_id); + T::ChildBountyManager::bounty_removed(bounty_id); Self::deposit_event(Event::::BountyClaimed { index: bounty_id, @@ -775,7 +779,9 @@ pub mod pallet { AllowDeath, ); // should not fail debug_assert!(res.is_ok()); + *maybe_bounty = None; + T::ChildBountyManager::bounty_removed(bounty_id); Self::deposit_event(Event::::BountyCanceled { index: bounty_id }); Ok(Some(>::WeightInfo::close_bounty_active()).into()) @@ -1053,4 +1059,6 @@ impl ChildBountyManager for () { fn children_curator_fees(_bounty_id: BountyIndex) -> Balance { Zero::zero() } + + fn bounty_removed(_bounty_id: BountyIndex) {} } diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 87f80bfe7ca7d..810b95497fda1 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -506,13 +506,12 @@ pub mod pallet { let child_bounty = maybe_child_bounty.as_mut().ok_or(BountiesError::::InvalidIndex)?; - let slash_curator = - |curator: &T::AccountId, curator_deposit: &mut BalanceOf| { - let imbalance = - T::Currency::slash_reserved(curator, *curator_deposit).0; - T::OnSlash::on_unbalanced(imbalance); - *curator_deposit = Zero::zero(); - }; + let slash_curator = |curator: &T::AccountId, + curator_deposit: &mut BalanceOf| { + let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; + T::OnSlash::on_unbalanced(imbalance); + *curator_deposit = Zero::zero(); + }; match child_bounty.status { ChildBountyStatus::Added => { @@ -960,4 +959,14 @@ impl pallet_bounties::ChildBountyManager> for Pallet ChildrenCuratorFees::::remove(bounty_id); children_fee_total } + + /// Clean up the storage on a parent bounty removal. + fn bounty_removed(bounty_id: BountyIndex) { + debug_assert!(ParentChildBounties::::get(bounty_id).is_zero()); + debug_assert!(ChildrenCuratorFees::::get(bounty_id).is_zero()); + debug_assert!(ChildBounties::::iter_key_prefix(bounty_id).count().is_zero()); + debug_assert!(ChildBountyDescriptionsV2::::iter_key_prefix(bounty_id).count().is_zero()); + ParentChildBounties::::remove(bounty_id); + ParentTotalChildBounties::::remove(bounty_id); + } } diff --git a/substrate/frame/child-bounties/src/tests.rs b/substrate/frame/child-bounties/src/tests.rs index 032685163ef73..d42eccf9eb22e 100644 --- a/substrate/frame/child-bounties/src/tests.rs +++ b/substrate/frame/child-bounties/src/tests.rs @@ -1154,10 +1154,14 @@ fn close_parent_with_child_bounty() { // Check the child-bounty count. assert_eq!(pallet_child_bounties::ParentChildBounties::::get(0), 0); + assert_eq!(pallet_child_bounties::ParentTotalChildBounties::::get(0), 1); // Try close parent-bounty again. // Should pass this time. assert_ok!(Bounties::close_bounty(RuntimeOrigin::root(), 0)); + + // Check the total count is removed after the parent bounty removal. + assert_eq!(pallet_child_bounties::ParentTotalChildBounties::::get(0), 0); }); } @@ -1236,9 +1240,15 @@ fn children_curator_fee_calculation_test() { go_to_block(15); + // Check the total count. + assert_eq!(pallet_child_bounties::ParentTotalChildBounties::::get(0), 1); + // Claim the parent bounty. assert_ok!(Bounties::claim_bounty(RuntimeOrigin::signed(9), 0)); + // Check the total count after the parent bounty removal. + assert_eq!(pallet_child_bounties::ParentTotalChildBounties::::get(0), 0); + // Ensure parent-bounty curator received correctly reduced fee. assert_eq!(Balances::free_balance(4), 101 + 6 - fee); // 101 + 6 - 2 assert_eq!(Balances::reserved_balance(4), 0); From 03ef2821be8a79e6ea92446f205021bca2ba50d1 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 5 Nov 2024 16:00:25 +0100 Subject: [PATCH 23/36] renames --- substrate/frame/child-bounties/src/lib.rs | 20 +++++++++++-------- .../frame/child-bounties/src/migration.rs | 8 ++++---- substrate/frame/child-bounties/src/tests.rs | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 810b95497fda1..f2fa9ff1b335b 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -220,8 +220,10 @@ pub mod pallet { >; /// The description of each child-bounty. + /// + /// This item replaces the `ChildBountyDescriptions` storage item from the V0 storage version. #[pallet::storage] - pub type ChildBountyDescriptionsV2 = StorageDoubleMap< + pub type ChildBountyDescriptionsV1 = StorageDoubleMap< _, Twox64Concat, BountyIndex, @@ -230,10 +232,12 @@ pub mod pallet { BoundedVec, >; - /// Stores a mapping of `old_child_bounty_id` generated from deprecated `ChildBountyCount` - /// storage item to new pair of parent/child ids (`parent_bounty_id`, `new_child_bounty_id`) + /// The mapping of the child bounty ids from storage version `V0` to the new `V1` version. + /// + /// The `V0` ids based on total child bounty count [`ChildBountyCount`]`. The `V1` version ids + /// based on the child bounty count per parent bounty [`ParentTotalChildBounties`]. #[pallet::storage] - pub type OldToNewChildBountyIds = + pub type V0ToV1ChildBountyIds = StorageMap<_, Twox64Concat, BountyIndex, (BountyIndex, BountyIndex)>; /// The cumulative child-bounty curator fee for each parent bounty. @@ -746,7 +750,7 @@ pub mod pallet { }); // Remove the child-bounty description. - ChildBountyDescriptionsV2::::remove(parent_bounty_id, child_bounty_id); + ChildBountyDescriptionsV1::::remove(parent_bounty_id, child_bounty_id); // Remove the child-bounty instance from the state. *maybe_child_bounty = None; @@ -851,7 +855,7 @@ impl Pallet { status: ChildBountyStatus::Added, }; ChildBounties::::insert(parent_bounty_id, child_bounty_id, &child_bounty); - ChildBountyDescriptionsV2::::insert(parent_bounty_id, child_bounty_id, description); + ChildBountyDescriptionsV1::::insert(parent_bounty_id, child_bounty_id, description); Self::deposit_event(Event::Added { index: parent_bounty_id, child_index: child_bounty_id }); } @@ -922,7 +926,7 @@ impl Pallet { debug_assert!(transfer_result.is_ok()); // Remove the child-bounty description. - ChildBountyDescriptionsV2::::remove(parent_bounty_id, child_bounty_id); + ChildBountyDescriptionsV1::::remove(parent_bounty_id, child_bounty_id); *maybe_child_bounty = None; @@ -965,7 +969,7 @@ impl pallet_bounties::ChildBountyManager> for Pallet debug_assert!(ParentChildBounties::::get(bounty_id).is_zero()); debug_assert!(ChildrenCuratorFees::::get(bounty_id).is_zero()); debug_assert!(ChildBounties::::iter_key_prefix(bounty_id).count().is_zero()); - debug_assert!(ChildBountyDescriptionsV2::::iter_key_prefix(bounty_id).count().is_zero()); + debug_assert!(ChildBountyDescriptionsV1::::iter_key_prefix(bounty_id).count().is_zero()); ParentChildBounties::::remove(bounty_id); ParentTotalChildBounties::::remove(bounty_id); } diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs index 4fd8d7b2d9e8c..eeabbf9354190 100644 --- a/substrate/frame/child-bounties/src/migration.rs +++ b/substrate/frame/child-bounties/src/migration.rs @@ -33,7 +33,7 @@ pub mod v1 { /// Migration to index `ChildBountyDescriptions` by parent bounty in a `StorageDoubleMap`. /// Reassigns new ids for child bounties composed of `(parent_bounty_id, child_bounty_id)`. - /// Creates a map of `OldToNewChildBountyIds` to find new child bounty id from old child bounty + /// Creates a map of `V0ToV1ChildBountyIds` to find new child bounty id from old child bounty /// id. /// /// `TransferWeight` returns `Weight` of `unreserve_balance` operation which is perfomed during @@ -81,7 +81,7 @@ pub mod v1 { ); writes += 1; - OldToNewChildBountyIds::::insert( + V0ToV1ChildBountyIds::::insert( old_child_bounty_id, (parent_bounty_id, new_child_bounty_id), ); @@ -134,7 +134,7 @@ pub mod v1 { ); } if let Some(bounty_description) = bounty_description { - super::super::ChildBountyDescriptionsV2::::insert( + super::super::ChildBountyDescriptionsV1::::insert( parent_bounty_id, new_child_bounty_id, bounty_description, @@ -174,7 +174,7 @@ pub mod v1 { StateType::decode(&mut &state[..]).expect("Can't decode previous state"); let new_child_bounty_count = ChildBounties::::iter_keys().count() as u32; let new_child_bounty_descriptions = - super::super::ChildBountyDescriptionsV2::::iter_keys().count() as u32; + super::super::ChildBountyDescriptionsV1::::iter_keys().count() as u32; ensure!( old_child_bounty_count == new_child_bounty_count, diff --git a/substrate/frame/child-bounties/src/tests.rs b/substrate/frame/child-bounties/src/tests.rs index d42eccf9eb22e..61dede610ae20 100644 --- a/substrate/frame/child-bounties/src/tests.rs +++ b/substrate/frame/child-bounties/src/tests.rs @@ -269,7 +269,7 @@ fn add_child_bounty() { // Check the child-bounty description status. assert_eq!( - pallet_child_bounties::ChildBountyDescriptionsV2::::get(0, 0).unwrap(), + pallet_child_bounties::ChildBountyDescriptionsV1::::get(0, 0).unwrap(), b"12345-p1".to_vec(), ); }); From 03409b230c7545188384e090fddf173f8cc6cce6 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 5 Nov 2024 16:09:44 +0100 Subject: [PATCH 24/36] update the prdoc --- prdoc/pr_6255.prdoc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/prdoc/pr_6255.prdoc b/prdoc/pr_6255.prdoc index 0042e5b77e282..0e66d952b225d 100644 --- a/prdoc/pr_6255.prdoc +++ b/prdoc/pr_6255.prdoc @@ -2,17 +2,19 @@ title: '[pallet-child-bounties] Index child bounties by parent bounty' doc: - audience: Runtime Dev description: | - Indexes child bounties by parent bounty. This allows to quickly - list child bounties and their descriptions from the parent bounty - by changing `ChildBountyDescriptions` to use `StorageDoubleMap` - which is indexed by `(ParentBounty, ChildBounty)` keys. + Index child bounties by their parent bounty, ensuring that their indexes are independent of + child bounties from other parent bounties. This will allow for predictable indexes and the + ability to batch creation and approval calls together. - - Changes child bounty keys in `ChildBounties` storage item. - - Deprecates `ChildBountyCount` storage item in May 2025. - - Migration is provided to migrate `ChildBountyDescriptions` and - `ChildBounties` storage items. - - Old pre-migration ids mapping is stored in the `OldToNewChildBountyIds` - storage item. + - Introduces `ParentTotalChildBounties` storage item to keep the total child bounty count per + parent bounty; + - Translates `ChildBounties` keys from (parent_id, old_child_id) to (parent_id, new_child_id); + - Replaces `ChildBountyDescriptions` storage item by new `ChildBountyDescriptionsV1` storage + item indexed by (parent_id, child_id) instead of (child_id); + - `V0ToV1ChildBountyIds` storage item provides the old_child_id -> parent_id, new_child_id + mapping; + - Deprecates `ChildBountyCount` storage item which will be removed in May 2025; + - Provides the migration from v0 to new v1 storage version. crates: - name: pallet-child-bounties bump: major From 67a09bc581969e25895cfcb9794493ae9361ae0d Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 5 Nov 2024 16:14:05 +0100 Subject: [PATCH 25/36] update the prdoc --- prdoc/pr_6255.prdoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/prdoc/pr_6255.prdoc b/prdoc/pr_6255.prdoc index 0e66d952b225d..8b822940aac1c 100644 --- a/prdoc/pr_6255.prdoc +++ b/prdoc/pr_6255.prdoc @@ -18,3 +18,7 @@ doc: crates: - name: pallet-child-bounties bump: major +- name: pallet-bounties + bump: major +- name: rococo-runtime + bump: major From e4edfcf8744c5e3c83823ba6a2e519cb57bd9dd2 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 5 Nov 2024 16:33:25 +0100 Subject: [PATCH 26/36] update migration doc --- substrate/frame/child-bounties/src/migration.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/substrate/frame/child-bounties/src/migration.rs b/substrate/frame/child-bounties/src/migration.rs index eeabbf9354190..52232a5a7f2fc 100644 --- a/substrate/frame/child-bounties/src/migration.rs +++ b/substrate/frame/child-bounties/src/migration.rs @@ -31,13 +31,13 @@ use frame_support::ensure; pub mod v1 { use super::*; - /// Migration to index `ChildBountyDescriptions` by parent bounty in a `StorageDoubleMap`. - /// Reassigns new ids for child bounties composed of `(parent_bounty_id, child_bounty_id)`. - /// Creates a map of `V0ToV1ChildBountyIds` to find new child bounty id from old child bounty - /// id. + /// Creates a new ids for the child balances based on the child bounty count per parent bounty + /// instead of the total child bounty count. Translates the existing child bounties to the new + /// ids. Creates the `V0ToV1ChildBountyIds` map from `old_child_id` to new (`parent_id`, + /// `new_child_id`). /// - /// `TransferWeight` returns `Weight` of `unreserve_balance` operation which is perfomed during - /// this migration. + /// `TransferWeight` returns `Weight` of `T::Currency::transfer` and `T::Currency::free_balance` + /// operation which is performed during this migration. pub struct MigrateToV1Impl(PhantomData<(T, TransferWeight)>); #[storage_alias] From 9d3d3191c0eb25b0ea6d5d416066eab626e391bb Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 5 Nov 2024 16:33:38 +0100 Subject: [PATCH 27/36] fmt --- substrate/frame/bounties/src/lib.rs | 12 ++++++------ substrate/frame/child-bounties/src/lib.rs | 13 +++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/substrate/frame/bounties/src/lib.rs b/substrate/frame/bounties/src/lib.rs index b5cc0421f692c..47cf7c4b55457 100644 --- a/substrate/frame/bounties/src/lib.rs +++ b/substrate/frame/bounties/src/lib.rs @@ -470,12 +470,12 @@ pub mod pallet { Bounties::::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult { let bounty = maybe_bounty.as_mut().ok_or(Error::::InvalidIndex)?; - let slash_curator = |curator: &T::AccountId, - curator_deposit: &mut BalanceOf| { - let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; - T::OnSlash::on_unbalanced(imbalance); - *curator_deposit = Zero::zero(); - }; + let slash_curator = + |curator: &T::AccountId, curator_deposit: &mut BalanceOf| { + let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; + T::OnSlash::on_unbalanced(imbalance); + *curator_deposit = Zero::zero(); + }; match bounty.status { BountyStatus::Proposed | BountyStatus::Approved | BountyStatus::Funded => { diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index f2fa9ff1b335b..c789c35d41077 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -510,12 +510,13 @@ pub mod pallet { let child_bounty = maybe_child_bounty.as_mut().ok_or(BountiesError::::InvalidIndex)?; - let slash_curator = |curator: &T::AccountId, - curator_deposit: &mut BalanceOf| { - let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; - T::OnSlash::on_unbalanced(imbalance); - *curator_deposit = Zero::zero(); - }; + let slash_curator = + |curator: &T::AccountId, curator_deposit: &mut BalanceOf| { + let imbalance = + T::Currency::slash_reserved(curator, *curator_deposit).0; + T::OnSlash::on_unbalanced(imbalance); + *curator_deposit = Zero::zero(); + }; match child_bounty.status { ChildBountyStatus::Added => { From d846af285f7c9af3e645beff954eb7cd52f916ab Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 5 Nov 2024 16:54:09 +0100 Subject: [PATCH 28/36] fmt --- substrate/frame/bounties/src/lib.rs | 2 +- substrate/frame/child-bounties/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/frame/bounties/src/lib.rs b/substrate/frame/bounties/src/lib.rs index 47cf7c4b55457..3ed408a19120a 100644 --- a/substrate/frame/bounties/src/lib.rs +++ b/substrate/frame/bounties/src/lib.rs @@ -470,7 +470,7 @@ pub mod pallet { Bounties::::try_mutate_exists(bounty_id, |maybe_bounty| -> DispatchResult { let bounty = maybe_bounty.as_mut().ok_or(Error::::InvalidIndex)?; - let slash_curator = + let slash_curator = |curator: &T::AccountId, curator_deposit: &mut BalanceOf| { let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; T::OnSlash::on_unbalanced(imbalance); diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index c789c35d41077..83e5b678aecca 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -512,7 +512,7 @@ pub mod pallet { let slash_curator = |curator: &T::AccountId, curator_deposit: &mut BalanceOf| { - let imbalance = + let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; T::OnSlash::on_unbalanced(imbalance); *curator_deposit = Zero::zero(); From f87bacc2ee20677e8b9ead9e28da2065c6b7ada9 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 5 Nov 2024 17:06:07 +0100 Subject: [PATCH 29/36] fmt --- substrate/frame/child-bounties/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 83e5b678aecca..0991273c92aab 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -510,7 +510,7 @@ pub mod pallet { let child_bounty = maybe_child_bounty.as_mut().ok_or(BountiesError::::InvalidIndex)?; - let slash_curator = + let slash_curator = |curator: &T::AccountId, curator_deposit: &mut BalanceOf| { let imbalance = T::Currency::slash_reserved(curator, *curator_deposit).0; From 5ed6eca83ac3e0802f59e45e4888263465ad1e8d Mon Sep 17 00:00:00 2001 From: Muharem Date: Tue, 5 Nov 2024 18:37:42 +0100 Subject: [PATCH 30/36] Update substrate/frame/child-bounties/src/lib.rs Co-authored-by: Oliver Tale-Yazdi --- substrate/frame/child-bounties/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 0991273c92aab..6c5191e01ab6c 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -219,7 +219,7 @@ pub mod pallet { ChildBounty, BlockNumberFor>, >; - /// The description of each child-bounty. + /// The description of each child-bounty. Indexed by `(parent_id, child_id)`. /// /// This item replaces the `ChildBountyDescriptions` storage item from the V0 storage version. #[pallet::storage] From 94ee08c19173c7ffd296a0583c576d6a7956ab06 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 5 Nov 2024 18:48:34 +0100 Subject: [PATCH 31/36] update the doc --- substrate/frame/child-bounties/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 6c5191e01ab6c..2772148ef42d5 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -236,6 +236,7 @@ pub mod pallet { /// /// The `V0` ids based on total child bounty count [`ChildBountyCount`]`. The `V1` version ids /// based on the child bounty count per parent bounty [`ParentTotalChildBounties`]. + /// The item intended solely for client convenience and not used in the pallet's core logic. #[pallet::storage] pub type V0ToV1ChildBountyIds = StorageMap<_, Twox64Concat, BountyIndex, (BountyIndex, BountyIndex)>; From 5567d19b7820a8184b82b66ae2c6051337dfef36 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 5 Nov 2024 19:59:13 +0100 Subject: [PATCH 32/36] use U256 as account id for the test env --- substrate/frame/child-bounties/src/tests.rs | 549 +++++++++++++------- 1 file changed, 362 insertions(+), 187 deletions(-) diff --git a/substrate/frame/child-bounties/src/tests.rs b/substrate/frame/child-bounties/src/tests.rs index f54486adf6110..130fccf5888a8 100644 --- a/substrate/frame/child-bounties/src/tests.rs +++ b/substrate/frame/child-bounties/src/tests.rs @@ -66,10 +66,16 @@ parameter_types! { } type Balance = u64; +// must be at least 20 bytes long because of child-bounty account derivation. +type AccountId = sp_core::U256; + +fn account_id(id: u8) -> AccountId { + sp_core::U256::from(id) +} #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { - type AccountId = u128; + type AccountId = AccountId; type Lookup = IdentityLookup; type Block = Block; type AccountData = pallet_balances::AccountData; @@ -82,14 +88,14 @@ impl pallet_balances::Config for Test { parameter_types! { pub const Burn: Permill = Permill::from_percent(50); pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); - pub TreasuryAccount: u128 = Treasury::account_id(); + pub TreasuryAccount: AccountId = Treasury::account_id(); pub const SpendLimit: Balance = u64::MAX; } impl pallet_treasury::Config for Test { type PalletId = TreasuryPalletId; type Currency = pallet_balances::Pallet; - type RejectOrigin = frame_system::EnsureRoot; + type RejectOrigin = frame_system::EnsureRoot; type RuntimeEvent = RuntimeEvent; type SpendPeriod = ConstU64<2>; type Burn = Burn; @@ -141,7 +147,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); pallet_balances::GenesisConfig:: { // Total issuance will be 200 with treasury account initialized at ED. - balances: vec![(0, 100), (1, 98), (2, 1)], + balances: vec![(account_id(0), 100), (account_id(1), 98), (account_id(2), 1)], } .assimilate_storage(&mut t) .unwrap(); @@ -195,52 +201,71 @@ fn add_child_bounty() { go_to_block(1); Balances::make_free_balance_be(&Treasury::account_id(), 101); - assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec())); + assert_ok!(Bounties::propose_bounty( + RuntimeOrigin::signed(account_id(0)), + 50, + b"12345".to_vec() + )); assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0)); go_to_block(2); let fee = 8; - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, fee)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(4), fee)); - Balances::make_free_balance_be(&4, 10); + Balances::make_free_balance_be(&account_id(4), 10); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(4)), 0)); // This verifies that the accept curator logic took a deposit. let expected_deposit = CuratorDepositMultiplier::get() * fee; - assert_eq!(Balances::reserved_balance(&4), expected_deposit); - assert_eq!(Balances::free_balance(&4), 10 - expected_deposit); + assert_eq!(Balances::reserved_balance(&account_id(4)), expected_deposit); + assert_eq!(Balances::free_balance(&account_id(4)), 10 - expected_deposit); // Add child-bounty. // Acc-4 is the parent curator. // Call from invalid origin & check for error "RequireCurator". assert_noop!( - ChildBounties::add_child_bounty(RuntimeOrigin::signed(0), 0, 10, b"12345-p1".to_vec()), + ChildBounties::add_child_bounty( + RuntimeOrigin::signed(account_id(0)), + 0, + 10, + b"12345-p1".to_vec() + ), BountiesError::RequireCurator, ); // Update the parent curator balance. - Balances::make_free_balance_be(&4, 101); + Balances::make_free_balance_be(&account_id(4), 101); // parent curator fee is reserved on parent bounty account. assert_eq!(Balances::free_balance(Bounties::bounty_account_id(0)), 50); assert_eq!(Balances::reserved_balance(Bounties::bounty_account_id(0)), 0); assert_noop!( - ChildBounties::add_child_bounty(RuntimeOrigin::signed(4), 0, 50, b"12345-p1".to_vec()), + ChildBounties::add_child_bounty( + RuntimeOrigin::signed(account_id(4)), + 0, + 50, + b"12345-p1".to_vec() + ), TokenError::NotExpendable, ); assert_noop!( - ChildBounties::add_child_bounty(RuntimeOrigin::signed(4), 0, 100, b"12345-p1".to_vec()), + ChildBounties::add_child_bounty( + RuntimeOrigin::signed(account_id(4)), + 0, + 100, + b"12345-p1".to_vec() + ), Error::::InsufficientBountyBalance, ); // Add child-bounty with valid value, which can be funded by parent bounty. assert_ok!(ChildBounties::add_child_bounty( - RuntimeOrigin::signed(4), + RuntimeOrigin::signed(account_id(4)), 0, 10, b"12345-p1".to_vec() @@ -249,8 +274,8 @@ fn add_child_bounty() { // Check for the event child-bounty added. assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 }); - assert_eq!(Balances::free_balance(4), 101); - assert_eq!(Balances::reserved_balance(4), expected_deposit); + assert_eq!(Balances::free_balance(account_id(4)), 101); + assert_eq!(Balances::reserved_balance(account_id(4)), expected_deposit); // DB check. // Check the child-bounty status. @@ -287,18 +312,22 @@ fn child_bounty_assign_curator() { // Make the parent bounty. go_to_block(1); Balances::make_free_balance_be(&Treasury::account_id(), 101); - Balances::make_free_balance_be(&4, 101); - Balances::make_free_balance_be(&8, 101); + Balances::make_free_balance_be(&account_id(4), 101); + Balances::make_free_balance_be(&account_id(8), 101); - assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec())); + assert_ok!(Bounties::propose_bounty( + RuntimeOrigin::signed(account_id(0)), + 50, + b"12345".to_vec() + )); assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0)); go_to_block(2); let fee = 4; - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, fee)); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(4), fee)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(4)), 0)); // Bounty account status before adding child-bounty. assert_eq!(Balances::free_balance(Bounties::bounty_account_id(0)), 50); @@ -307,13 +336,13 @@ fn child_bounty_assign_curator() { // Check the balance of parent curator. // Curator deposit is reserved for parent curator on parent bounty. let expected_deposit = Bounties::calculate_curator_deposit(&fee); - assert_eq!(Balances::free_balance(4), 101 - expected_deposit); - assert_eq!(Balances::reserved_balance(4), expected_deposit); + assert_eq!(Balances::free_balance(account_id(4)), 101 - expected_deposit); + assert_eq!(Balances::reserved_balance(account_id(4)), expected_deposit); // Add child-bounty. // Acc-4 is the parent curator & make sure enough deposit. assert_ok!(ChildBounties::add_child_bounty( - RuntimeOrigin::signed(4), + RuntimeOrigin::signed(account_id(4)), 0, 10, b"12345-p1".to_vec() @@ -330,7 +359,13 @@ fn child_bounty_assign_curator() { assert_eq!(Balances::reserved_balance(ChildBounties::child_bounty_account_id(0, 0)), 0); let fee = 6u64; - assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee)); + assert_ok!(ChildBounties::propose_curator( + RuntimeOrigin::signed(account_id(4)), + 0, + 0, + account_id(8), + fee + )); assert_eq!( pallet_child_bounties::ChildBounties::::get(0, 0).unwrap(), @@ -339,20 +374,20 @@ fn child_bounty_assign_curator() { value: 10, fee, curator_deposit: 0, - status: ChildBountyStatus::CuratorProposed { curator: 8 }, + status: ChildBountyStatus::CuratorProposed { curator: account_id(8) }, } ); // Check the balance of parent curator. - assert_eq!(Balances::free_balance(4), 101 - expected_deposit); - assert_eq!(Balances::reserved_balance(4), expected_deposit); + assert_eq!(Balances::free_balance(account_id(4)), 101 - expected_deposit); + assert_eq!(Balances::reserved_balance(account_id(4)), expected_deposit); assert_noop!( - ChildBounties::accept_curator(RuntimeOrigin::signed(3), 0, 0), + ChildBounties::accept_curator(RuntimeOrigin::signed(account_id(3)), 0, 0), BountiesError::RequireCurator, ); - assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0)); + assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(account_id(8)), 0, 0)); let expected_child_deposit = CuratorDepositMultiplier::get() * fee; @@ -363,13 +398,13 @@ fn child_bounty_assign_curator() { value: 10, fee, curator_deposit: expected_child_deposit, - status: ChildBountyStatus::Active { curator: 8 }, + status: ChildBountyStatus::Active { curator: account_id(8) }, } ); // Deposit for child-bounty curator deposit is reserved. - assert_eq!(Balances::free_balance(8), 101 - expected_child_deposit); - assert_eq!(Balances::reserved_balance(8), expected_child_deposit); + assert_eq!(Balances::free_balance(account_id(8)), 101 - expected_child_deposit); + assert_eq!(Balances::reserved_balance(account_id(8)), expected_child_deposit); // Bounty account status at exit. assert_eq!(Balances::free_balance(Bounties::bounty_account_id(0)), 40); @@ -395,21 +430,25 @@ fn award_claim_child_bounty() { assert_eq!(Balances::reserved_balance(Treasury::account_id()), 0); // Bounty curator initial balance. - Balances::make_free_balance_be(&4, 101); // Parent-bounty curator. - Balances::make_free_balance_be(&8, 101); // Child-bounty curator. + Balances::make_free_balance_be(&account_id(4), 101); // Parent-bounty curator. + Balances::make_free_balance_be(&account_id(8), 101); // Child-bounty curator. - assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec())); + assert_ok!(Bounties::propose_bounty( + RuntimeOrigin::signed(account_id(0)), + 50, + b"12345".to_vec() + )); assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0)); go_to_block(2); - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6)); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(4), 6)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(4)), 0)); // Child-bounty. assert_ok!(ChildBounties::add_child_bounty( - RuntimeOrigin::signed(4), + RuntimeOrigin::signed(account_id(4)), 0, 10, b"12345-p1".to_vec() @@ -419,17 +458,33 @@ fn award_claim_child_bounty() { // Propose and accept curator for child-bounty. let fee = 8; - assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee)); - assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0)); + assert_ok!(ChildBounties::propose_curator( + RuntimeOrigin::signed(account_id(4)), + 0, + 0, + account_id(8), + fee + )); + assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(account_id(8)), 0, 0)); // Award child-bounty. // Test for non child-bounty curator. assert_noop!( - ChildBounties::award_child_bounty(RuntimeOrigin::signed(3), 0, 0, 7), + ChildBounties::award_child_bounty( + RuntimeOrigin::signed(account_id(3)), + 0, + 0, + account_id(7) + ), BountiesError::RequireCurator, ); - assert_ok!(ChildBounties::award_child_bounty(RuntimeOrigin::signed(8), 0, 0, 7)); + assert_ok!(ChildBounties::award_child_bounty( + RuntimeOrigin::signed(account_id(8)), + 0, + 0, + account_id(7) + )); let expected_deposit = CuratorDepositMultiplier::get() * fee; assert_eq!( @@ -440,8 +495,8 @@ fn award_claim_child_bounty() { fee, curator_deposit: expected_deposit, status: ChildBountyStatus::PendingPayout { - curator: 8, - beneficiary: 7, + curator: account_id(8), + beneficiary: account_id(7), unlock_at: 5 }, } @@ -450,21 +505,21 @@ fn award_claim_child_bounty() { // Claim child-bounty. // Test for Premature condition. assert_noop!( - ChildBounties::claim_child_bounty(RuntimeOrigin::signed(7), 0, 0), + ChildBounties::claim_child_bounty(RuntimeOrigin::signed(account_id(7)), 0, 0), BountiesError::Premature ); go_to_block(9); - assert_ok!(ChildBounties::claim_child_bounty(RuntimeOrigin::signed(7), 0, 0)); + assert_ok!(ChildBounties::claim_child_bounty(RuntimeOrigin::signed(account_id(7)), 0, 0)); // Ensure child-bounty curator is paid with curator fee & deposit refund. - assert_eq!(Balances::free_balance(8), 101 + fee); - assert_eq!(Balances::reserved_balance(8), 0); + assert_eq!(Balances::free_balance(account_id(8)), 101 + fee); + assert_eq!(Balances::reserved_balance(account_id(8)), 0); // Ensure executor is paid with beneficiary amount. - assert_eq!(Balances::free_balance(7), 10 - fee); - assert_eq!(Balances::reserved_balance(7), 0); + assert_eq!(Balances::free_balance(account_id(7)), 10 - fee); + assert_eq!(Balances::reserved_balance(account_id(7)), 0); // Child-bounty account status. assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0, 0)), 0); @@ -485,22 +540,26 @@ fn close_child_bounty_added() { assert_eq!(Balances::reserved_balance(Treasury::account_id()), 0); // Bounty curator initial balance. - Balances::make_free_balance_be(&4, 101); // Parent-bounty curator. - Balances::make_free_balance_be(&8, 101); // Child-bounty curator. + Balances::make_free_balance_be(&account_id(4), 101); // Parent-bounty curator. + Balances::make_free_balance_be(&account_id(8), 101); // Child-bounty curator. - assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec())); + assert_ok!(Bounties::propose_bounty( + RuntimeOrigin::signed(account_id(0)), + 50, + b"12345".to_vec() + )); assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0)); go_to_block(2); - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(4), 6)); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(4)), 0)); // Child-bounty. assert_ok!(ChildBounties::add_child_bounty( - RuntimeOrigin::signed(4), + RuntimeOrigin::signed(account_id(4)), 0, 10, b"12345-p1".to_vec() @@ -512,11 +571,17 @@ fn close_child_bounty_added() { // Close child-bounty. // Wrong origin. - assert_noop!(ChildBounties::close_child_bounty(RuntimeOrigin::signed(7), 0, 0), BadOrigin); - assert_noop!(ChildBounties::close_child_bounty(RuntimeOrigin::signed(8), 0, 0), BadOrigin); + assert_noop!( + ChildBounties::close_child_bounty(RuntimeOrigin::signed(account_id(7)), 0, 0), + BadOrigin + ); + assert_noop!( + ChildBounties::close_child_bounty(RuntimeOrigin::signed(account_id(8)), 0, 0), + BadOrigin + ); // Correct origin - parent curator. - assert_ok!(ChildBounties::close_child_bounty(RuntimeOrigin::signed(4), 0, 0)); + assert_ok!(ChildBounties::close_child_bounty(RuntimeOrigin::signed(account_id(4)), 0, 0)); // Check the child-bounty count. assert_eq!(pallet_child_bounties::ParentChildBounties::::get(0), 0); @@ -541,22 +606,26 @@ fn close_child_bounty_active() { assert_eq!(Balances::reserved_balance(Treasury::account_id()), 0); // Bounty curator initial balance. - Balances::make_free_balance_be(&4, 101); // Parent-bounty curator. - Balances::make_free_balance_be(&8, 101); // Child-bounty curator. + Balances::make_free_balance_be(&account_id(4), 101); // Parent-bounty curator. + Balances::make_free_balance_be(&account_id(8), 101); // Child-bounty curator. - assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec())); + assert_ok!(Bounties::propose_bounty( + RuntimeOrigin::signed(account_id(0)), + 50, + b"12345".to_vec() + )); assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0)); go_to_block(2); - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(4), 6)); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(4)), 0)); // Child-bounty. assert_ok!(ChildBounties::add_child_bounty( - RuntimeOrigin::signed(4), + RuntimeOrigin::signed(account_id(4)), 0, 10, b"12345-p1".to_vec() @@ -565,18 +634,24 @@ fn close_child_bounty_active() { assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 }); // Propose and accept curator for child-bounty. - assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, 2)); - assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0)); + assert_ok!(ChildBounties::propose_curator( + RuntimeOrigin::signed(account_id(4)), + 0, + 0, + account_id(8), + 2 + )); + assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(account_id(8)), 0, 0)); // Close child-bounty in active state. - assert_ok!(ChildBounties::close_child_bounty(RuntimeOrigin::signed(4), 0, 0)); + assert_ok!(ChildBounties::close_child_bounty(RuntimeOrigin::signed(account_id(4)), 0, 0)); // Check the child-bounty count. assert_eq!(pallet_child_bounties::ParentChildBounties::::get(0), 0); // Ensure child-bounty curator balance is unreserved. - assert_eq!(Balances::free_balance(8), 101); - assert_eq!(Balances::reserved_balance(8), 0); + assert_eq!(Balances::free_balance(account_id(8)), 101); + assert_eq!(Balances::reserved_balance(account_id(8)), 0); // Parent-bounty account status. assert_eq!(Balances::free_balance(Bounties::bounty_account_id(0)), 50); @@ -598,22 +673,26 @@ fn close_child_bounty_pending() { assert_eq!(Balances::reserved_balance(Treasury::account_id()), 0); // Bounty curator initial balance. - Balances::make_free_balance_be(&4, 101); // Parent-bounty curator. - Balances::make_free_balance_be(&8, 101); // Child-bounty curator. + Balances::make_free_balance_be(&account_id(4), 101); // Parent-bounty curator. + Balances::make_free_balance_be(&account_id(8), 101); // Child-bounty curator. - assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec())); + assert_ok!(Bounties::propose_bounty( + RuntimeOrigin::signed(account_id(0)), + 50, + b"12345".to_vec() + )); assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0)); go_to_block(2); let parent_fee = 6; - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, parent_fee)); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(4), parent_fee)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(4)), 0)); // Child-bounty. assert_ok!(ChildBounties::add_child_bounty( - RuntimeOrigin::signed(4), + RuntimeOrigin::signed(account_id(4)), 0, 10, b"12345-p1".to_vec() @@ -623,15 +702,26 @@ fn close_child_bounty_pending() { // Propose and accept curator for child-bounty. let child_fee = 4; - assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, child_fee)); - assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0)); + assert_ok!(ChildBounties::propose_curator( + RuntimeOrigin::signed(account_id(4)), + 0, + 0, + account_id(8), + child_fee + )); + assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(account_id(8)), 0, 0)); let expected_child_deposit = CuratorDepositMin::get(); - assert_ok!(ChildBounties::award_child_bounty(RuntimeOrigin::signed(8), 0, 0, 7)); + assert_ok!(ChildBounties::award_child_bounty( + RuntimeOrigin::signed(account_id(8)), + 0, + 0, + account_id(7) + )); // Close child-bounty in pending_payout state. assert_noop!( - ChildBounties::close_child_bounty(RuntimeOrigin::signed(4), 0, 0), + ChildBounties::close_child_bounty(RuntimeOrigin::signed(account_id(4)), 0, 0), BountiesError::PendingPayout ); @@ -639,8 +729,8 @@ fn close_child_bounty_pending() { assert_eq!(pallet_child_bounties::ParentChildBounties::::get(0), 1); // Ensure no changes in child-bounty curator balance. - assert_eq!(Balances::reserved_balance(8), expected_child_deposit); - assert_eq!(Balances::free_balance(8), 101 - expected_child_deposit); + assert_eq!(Balances::reserved_balance(account_id(8)), expected_child_deposit); + assert_eq!(Balances::free_balance(account_id(8)), 101 - expected_child_deposit); // Child-bounty account status. assert_eq!(Balances::free_balance(ChildBounties::child_bounty_account_id(0, 0)), 10); @@ -658,22 +748,26 @@ fn child_bounty_added_unassign_curator() { assert_eq!(Balances::reserved_balance(Treasury::account_id()), 0); // Bounty curator initial balance. - Balances::make_free_balance_be(&4, 101); // Parent-bounty curator. - Balances::make_free_balance_be(&8, 101); // Child-bounty curator. + Balances::make_free_balance_be(&account_id(4), 101); // Parent-bounty curator. + Balances::make_free_balance_be(&account_id(8), 101); // Child-bounty curator. - assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec())); + assert_ok!(Bounties::propose_bounty( + RuntimeOrigin::signed(account_id(0)), + 50, + b"12345".to_vec() + )); assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0)); go_to_block(2); - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(4), 6)); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(4)), 0)); // Child-bounty. assert_ok!(ChildBounties::add_child_bounty( - RuntimeOrigin::signed(4), + RuntimeOrigin::signed(account_id(4)), 0, 10, b"12345-p1".to_vec() @@ -683,7 +777,7 @@ fn child_bounty_added_unassign_curator() { // Unassign curator in added state. assert_noop!( - ChildBounties::unassign_curator(RuntimeOrigin::signed(4), 0, 0), + ChildBounties::unassign_curator(RuntimeOrigin::signed(account_id(4)), 0, 0), BountiesError::UnexpectedStatus ); }); @@ -699,22 +793,26 @@ fn child_bounty_curator_proposed_unassign_curator() { assert_eq!(Balances::reserved_balance(Treasury::account_id()), 0); // Bounty curator initial balance. - Balances::make_free_balance_be(&4, 101); // Parent-bounty curator. - Balances::make_free_balance_be(&8, 101); // Child-bounty curator. + Balances::make_free_balance_be(&account_id(4), 101); // Parent-bounty curator. + Balances::make_free_balance_be(&account_id(8), 101); // Child-bounty curator. - assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec())); + assert_ok!(Bounties::propose_bounty( + RuntimeOrigin::signed(account_id(0)), + 50, + b"12345".to_vec() + )); assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0)); go_to_block(2); - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(4), 6)); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(4)), 0)); // Child-bounty. assert_ok!(ChildBounties::add_child_bounty( - RuntimeOrigin::signed(4), + RuntimeOrigin::signed(account_id(4)), 0, 10, b"12345-p1".to_vec() @@ -723,7 +821,13 @@ fn child_bounty_curator_proposed_unassign_curator() { assert_eq!(last_event(), ChildBountiesEvent::Added { index: 0, child_index: 0 }); // Propose curator for child-bounty. - assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, 2)); + assert_ok!(ChildBounties::propose_curator( + RuntimeOrigin::signed(account_id(4)), + 0, + 0, + account_id(8), + 2 + )); assert_eq!( pallet_child_bounties::ChildBounties::::get(0, 0).unwrap(), @@ -732,15 +836,18 @@ fn child_bounty_curator_proposed_unassign_curator() { value: 10, fee: 2, curator_deposit: 0, - status: ChildBountyStatus::CuratorProposed { curator: 8 }, + status: ChildBountyStatus::CuratorProposed { curator: account_id(8) }, } ); // Random account cannot unassign the curator when in proposed state. - assert_noop!(ChildBounties::unassign_curator(RuntimeOrigin::signed(99), 0, 0), BadOrigin); + assert_noop!( + ChildBounties::unassign_curator(RuntimeOrigin::signed(account_id(99)), 0, 0), + BadOrigin + ); // Unassign curator. - assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(4), 0, 0)); + assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(account_id(4)), 0, 0)); // Verify updated child-bounty status. assert_eq!( @@ -773,23 +880,27 @@ fn child_bounty_active_unassign_curator() { assert_eq!(Balances::reserved_balance(Treasury::account_id()), 0); // Bounty curator initial balance. - Balances::make_free_balance_be(&4, 101); // Parent-bounty curator. - Balances::make_free_balance_be(&6, 101); // Child-bounty curator 1. - Balances::make_free_balance_be(&7, 101); // Child-bounty curator 2. - Balances::make_free_balance_be(&8, 101); // Child-bounty curator 3. + Balances::make_free_balance_be(&account_id(4), 101); // Parent-bounty curator. + Balances::make_free_balance_be(&account_id(6), 101); // Child-bounty curator 1. + Balances::make_free_balance_be(&account_id(7), 101); // Child-bounty curator 2. + Balances::make_free_balance_be(&account_id(8), 101); // Child-bounty curator 3. - assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec())); + assert_ok!(Bounties::propose_bounty( + RuntimeOrigin::signed(account_id(0)), + 50, + b"12345".to_vec() + )); assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0)); go_to_block(2); - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6)); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(4), 6)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(4)), 0)); // Create Child-bounty. assert_ok!(ChildBounties::add_child_bounty( - RuntimeOrigin::signed(4), + RuntimeOrigin::signed(account_id(4)), 0, 10, b"12345-p1".to_vec() @@ -800,8 +911,14 @@ fn child_bounty_active_unassign_curator() { // Propose and accept curator for child-bounty. let fee = 6; - assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee)); - assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0)); + assert_ok!(ChildBounties::propose_curator( + RuntimeOrigin::signed(account_id(4)), + 0, + 0, + account_id(8), + fee + )); + assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(account_id(8)), 0, 0)); let expected_child_deposit = CuratorDepositMultiplier::get() * fee; assert_eq!( @@ -811,7 +928,7 @@ fn child_bounty_active_unassign_curator() { value: 10, fee, curator_deposit: expected_child_deposit, - status: ChildBountyStatus::Active { curator: 8 }, + status: ChildBountyStatus::Active { curator: account_id(8) }, } ); @@ -833,13 +950,19 @@ fn child_bounty_active_unassign_curator() { ); // Ensure child-bounty curator was slashed. - assert_eq!(Balances::free_balance(8), 101 - expected_child_deposit); - assert_eq!(Balances::reserved_balance(8), 0); // slashed + assert_eq!(Balances::free_balance(account_id(8)), 101 - expected_child_deposit); + assert_eq!(Balances::reserved_balance(account_id(8)), 0); // slashed // Propose and accept curator for child-bounty again. let fee = 2; - assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 7, fee)); - assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(7), 0, 0)); + assert_ok!(ChildBounties::propose_curator( + RuntimeOrigin::signed(account_id(4)), + 0, + 0, + account_id(7), + fee + )); + assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(account_id(7)), 0, 0)); let expected_child_deposit = CuratorDepositMin::get(); assert_eq!( @@ -849,14 +972,14 @@ fn child_bounty_active_unassign_curator() { value: 10, fee, curator_deposit: expected_child_deposit, - status: ChildBountyStatus::Active { curator: 7 }, + status: ChildBountyStatus::Active { curator: account_id(7) }, } ); go_to_block(5); // Unassign curator again - from parent curator. - assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(4), 0, 0)); + assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(account_id(4)), 0, 0)); // Verify updated child-bounty status. assert_eq!( @@ -871,12 +994,18 @@ fn child_bounty_active_unassign_curator() { ); // Ensure child-bounty curator was slashed. - assert_eq!(Balances::free_balance(7), 101 - expected_child_deposit); - assert_eq!(Balances::reserved_balance(7), 0); // slashed + assert_eq!(Balances::free_balance(account_id(7)), 101 - expected_child_deposit); + assert_eq!(Balances::reserved_balance(account_id(7)), 0); // slashed // Propose and accept curator for child-bounty again. - assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 6, 2)); - assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(6), 0, 0)); + assert_ok!(ChildBounties::propose_curator( + RuntimeOrigin::signed(account_id(4)), + 0, + 0, + account_id(6), + 2 + )); + assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(account_id(6)), 0, 0)); assert_eq!( pallet_child_bounties::ChildBounties::::get(0, 0).unwrap(), @@ -885,14 +1014,14 @@ fn child_bounty_active_unassign_curator() { value: 10, fee, curator_deposit: expected_child_deposit, - status: ChildBountyStatus::Active { curator: 6 }, + status: ChildBountyStatus::Active { curator: account_id(6) }, } ); go_to_block(6); // Unassign curator again - from child-bounty curator. - assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(6), 0, 0)); + assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(account_id(6)), 0, 0)); // Verify updated child-bounty status. assert_eq!( @@ -907,13 +1036,19 @@ fn child_bounty_active_unassign_curator() { ); // Ensure child-bounty curator was **not** slashed. - assert_eq!(Balances::free_balance(6), 101); // not slashed - assert_eq!(Balances::reserved_balance(6), 0); + assert_eq!(Balances::free_balance(account_id(6)), 101); // not slashed + assert_eq!(Balances::reserved_balance(account_id(6)), 0); // Propose and accept curator for child-bounty one last time. let fee = 2; - assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 6, fee)); - assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(6), 0, 0)); + assert_ok!(ChildBounties::propose_curator( + RuntimeOrigin::signed(account_id(4)), + 0, + 0, + account_id(6), + fee + )); + assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(account_id(6)), 0, 0)); let expected_child_deposit = CuratorDepositMin::get(); assert_eq!( @@ -923,7 +1058,7 @@ fn child_bounty_active_unassign_curator() { value: 10, fee, curator_deposit: expected_child_deposit, - status: ChildBountyStatus::Active { curator: 6 }, + status: ChildBountyStatus::Active { curator: account_id(6) }, } ); @@ -932,14 +1067,14 @@ fn child_bounty_active_unassign_curator() { // Unassign curator again - from non curator; non reject origin; some random guy. // Bounty update period is not yet complete. assert_noop!( - ChildBounties::unassign_curator(RuntimeOrigin::signed(3), 0, 0), + ChildBounties::unassign_curator(RuntimeOrigin::signed(account_id(3)), 0, 0), BountiesError::Premature ); go_to_block(20); // Unassign child curator from random account after inactivity. - assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(3), 0, 0)); + assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(account_id(3)), 0, 0)); // Verify updated child-bounty status. assert_eq!( @@ -954,8 +1089,8 @@ fn child_bounty_active_unassign_curator() { ); // Ensure child-bounty curator was slashed. - assert_eq!(Balances::free_balance(6), 101 - expected_child_deposit); // slashed - assert_eq!(Balances::reserved_balance(6), 0); + assert_eq!(Balances::free_balance(account_id(6)), 101 - expected_child_deposit); // slashed + assert_eq!(Balances::reserved_balance(account_id(6)), 0); }); } @@ -971,23 +1106,27 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() { assert_eq!(Balances::reserved_balance(Treasury::account_id()), 0); // Bounty curator initial balance. - Balances::make_free_balance_be(&4, 101); // Parent-bounty curator 1. - Balances::make_free_balance_be(&5, 101); // Parent-bounty curator 2. - Balances::make_free_balance_be(&6, 101); // Child-bounty curator 1. - Balances::make_free_balance_be(&7, 101); // Child-bounty curator 2. - Balances::make_free_balance_be(&8, 101); // Child-bounty curator 3. + Balances::make_free_balance_be(&account_id(4), 101); // Parent-bounty curator 1. + Balances::make_free_balance_be(&account_id(5), 101); // Parent-bounty curator 2. + Balances::make_free_balance_be(&account_id(6), 101); // Child-bounty curator 1. + Balances::make_free_balance_be(&account_id(7), 101); // Child-bounty curator 2. + Balances::make_free_balance_be(&account_id(8), 101); // Child-bounty curator 3. - assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec())); + assert_ok!(Bounties::propose_bounty( + RuntimeOrigin::signed(account_id(0)), + 50, + b"12345".to_vec() + )); assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0)); go_to_block(2); - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6)); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(4), 6)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(4)), 0)); // Create Child-bounty. assert_ok!(ChildBounties::add_child_bounty( - RuntimeOrigin::signed(4), + RuntimeOrigin::signed(account_id(4)), 0, 10, b"12345-p1".to_vec() @@ -998,8 +1137,14 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() { // Propose and accept curator for child-bounty. let fee = 8; - assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee)); - assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0)); + assert_ok!(ChildBounties::propose_curator( + RuntimeOrigin::signed(account_id(4)), + 0, + 0, + account_id(8), + fee + )); + assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(account_id(8)), 0, 0)); let expected_child_deposit = CuratorDepositMultiplier::get() * fee; assert_eq!( @@ -1009,7 +1154,7 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() { value: 10, fee, curator_deposit: expected_child_deposit, - status: ChildBountyStatus::Active { curator: 8 }, + status: ChildBountyStatus::Active { curator: account_id(8) }, } ); @@ -1023,7 +1168,7 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() { // Try unassign child-bounty curator - from non curator; non reject // origin; some random guy. Bounty update period is not yet complete. assert_noop!( - ChildBounties::unassign_curator(RuntimeOrigin::signed(3), 0, 0), + ChildBounties::unassign_curator(RuntimeOrigin::signed(account_id(3)), 0, 0), Error::::ParentBountyNotActive ); @@ -1043,21 +1188,27 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() { ); // Ensure child-bounty curator was slashed. - assert_eq!(Balances::free_balance(8), 101 - expected_child_deposit); - assert_eq!(Balances::reserved_balance(8), 0); // slashed + assert_eq!(Balances::free_balance(account_id(8)), 101 - expected_child_deposit); + assert_eq!(Balances::reserved_balance(account_id(8)), 0); // slashed go_to_block(6); // Propose and accept curator for parent-bounty again. - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 5, 6)); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(5), 0)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(5), 6)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(5)), 0)); go_to_block(7); // Propose and accept curator for child-bounty again. let fee = 2; - assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(5), 0, 0, 7, fee)); - assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(7), 0, 0)); + assert_ok!(ChildBounties::propose_curator( + RuntimeOrigin::signed(account_id(5)), + 0, + 0, + account_id(7), + fee + )); + assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(account_id(7)), 0, 0)); let expected_deposit = CuratorDepositMin::get(); assert_eq!( @@ -1067,24 +1218,24 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() { value: 10, fee, curator_deposit: expected_deposit, - status: ChildBountyStatus::Active { curator: 7 }, + status: ChildBountyStatus::Active { curator: account_id(7) }, } ); go_to_block(8); assert_noop!( - ChildBounties::unassign_curator(RuntimeOrigin::signed(3), 0, 0), + ChildBounties::unassign_curator(RuntimeOrigin::signed(account_id(3)), 0, 0), BountiesError::Premature ); // Unassign parent bounty curator again. - assert_ok!(Bounties::unassign_curator(RuntimeOrigin::signed(5), 0)); + assert_ok!(Bounties::unassign_curator(RuntimeOrigin::signed(account_id(5)), 0)); go_to_block(9); // Unassign curator again - from parent curator. - assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(7), 0, 0)); + assert_ok!(ChildBounties::unassign_curator(RuntimeOrigin::signed(account_id(7)), 0, 0)); // Verify updated child-bounty status. assert_eq!( @@ -1099,8 +1250,8 @@ fn parent_bounty_inactive_unassign_curator_child_bounty() { ); // Ensure child-bounty curator was not slashed. - assert_eq!(Balances::free_balance(7), 101); - assert_eq!(Balances::reserved_balance(7), 0); // slashed + assert_eq!(Balances::free_balance(account_id(7)), 101); + assert_eq!(Balances::reserved_balance(account_id(7)), 0); // slashed }); } @@ -1114,27 +1265,36 @@ fn close_parent_with_child_bounty() { assert_eq!(Balances::reserved_balance(Treasury::account_id()), 0); // Bounty curator initial balance. - Balances::make_free_balance_be(&4, 101); // Parent-bounty curator. - Balances::make_free_balance_be(&8, 101); // Child-bounty curator. + Balances::make_free_balance_be(&account_id(4), 101); // Parent-bounty curator. + Balances::make_free_balance_be(&account_id(8), 101); // Child-bounty curator. - assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec())); + assert_ok!(Bounties::propose_bounty( + RuntimeOrigin::signed(account_id(0)), + 50, + b"12345".to_vec() + )); assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0)); // Try add child-bounty. // Should fail, parent bounty not active yet. assert_noop!( - ChildBounties::add_child_bounty(RuntimeOrigin::signed(4), 0, 10, b"12345-p1".to_vec()), + ChildBounties::add_child_bounty( + RuntimeOrigin::signed(account_id(4)), + 0, + 10, + b"12345-p1".to_vec() + ), Error::::ParentBountyNotActive ); go_to_block(2); - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6)); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(4), 6)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(4)), 0)); // Child-bounty. assert_ok!(ChildBounties::add_child_bounty( - RuntimeOrigin::signed(4), + RuntimeOrigin::signed(account_id(4)), 0, 10, b"12345-p1".to_vec() @@ -1178,20 +1338,24 @@ fn children_curator_fee_calculation_test() { assert_eq!(Balances::reserved_balance(Treasury::account_id()), 0); // Bounty curator initial balance. - Balances::make_free_balance_be(&4, 101); // Parent-bounty curator. - Balances::make_free_balance_be(&8, 101); // Child-bounty curator. + Balances::make_free_balance_be(&account_id(4), 101); // Parent-bounty curator. + Balances::make_free_balance_be(&account_id(8), 101); // Child-bounty curator. - assert_ok!(Bounties::propose_bounty(RuntimeOrigin::signed(0), 50, b"12345".to_vec())); + assert_ok!(Bounties::propose_bounty( + RuntimeOrigin::signed(account_id(0)), + 50, + b"12345".to_vec() + )); assert_ok!(Bounties::approve_bounty(RuntimeOrigin::root(), 0)); go_to_block(2); - assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, 4, 6)); - assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(4), 0)); + assert_ok!(Bounties::propose_curator(RuntimeOrigin::root(), 0, account_id(4), 6)); + assert_ok!(Bounties::accept_curator(RuntimeOrigin::signed(account_id(4)), 0)); // Child-bounty. assert_ok!(ChildBounties::add_child_bounty( - RuntimeOrigin::signed(4), + RuntimeOrigin::signed(account_id(4)), 0, 10, b"12345-p1".to_vec() @@ -1203,13 +1367,24 @@ fn children_curator_fee_calculation_test() { let fee = 6; // Propose curator for child-bounty. - assert_ok!(ChildBounties::propose_curator(RuntimeOrigin::signed(4), 0, 0, 8, fee)); + assert_ok!(ChildBounties::propose_curator( + RuntimeOrigin::signed(account_id(4)), + 0, + 0, + account_id(8), + fee + )); // Check curator fee added to the sum. assert_eq!(pallet_child_bounties::ChildrenCuratorFees::::get(0), fee); // Accept curator for child-bounty. - assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(8), 0, 0)); + assert_ok!(ChildBounties::accept_curator(RuntimeOrigin::signed(account_id(8)), 0, 0)); // Award child-bounty. - assert_ok!(ChildBounties::award_child_bounty(RuntimeOrigin::signed(8), 0, 0, 7)); + assert_ok!(ChildBounties::award_child_bounty( + RuntimeOrigin::signed(account_id(8)), + 0, + 0, + account_id(7) + )); let expected_child_deposit = CuratorDepositMultiplier::get() * fee; @@ -1221,8 +1396,8 @@ fn children_curator_fee_calculation_test() { fee, curator_deposit: expected_child_deposit, status: ChildBountyStatus::PendingPayout { - curator: 8, - beneficiary: 7, + curator: account_id(8), + beneficiary: account_id(7), unlock_at: 7 }, } @@ -1231,13 +1406,13 @@ fn children_curator_fee_calculation_test() { go_to_block(9); // Claim child-bounty. - assert_ok!(ChildBounties::claim_child_bounty(RuntimeOrigin::signed(7), 0, 0)); + assert_ok!(ChildBounties::claim_child_bounty(RuntimeOrigin::signed(account_id(7)), 0, 0)); // Check the child-bounty count. assert_eq!(pallet_child_bounties::ParentChildBounties::::get(0), 0); // Award the parent bounty. - assert_ok!(Bounties::award_bounty(RuntimeOrigin::signed(4), 0, 9)); + assert_ok!(Bounties::award_bounty(RuntimeOrigin::signed(account_id(4)), 0, account_id(9))); go_to_block(15); @@ -1245,18 +1420,18 @@ fn children_curator_fee_calculation_test() { assert_eq!(pallet_child_bounties::ParentTotalChildBounties::::get(0), 1); // Claim the parent bounty. - assert_ok!(Bounties::claim_bounty(RuntimeOrigin::signed(9), 0)); + assert_ok!(Bounties::claim_bounty(RuntimeOrigin::signed(account_id(9)), 0)); // Check the total count after the parent bounty removal. assert_eq!(pallet_child_bounties::ParentTotalChildBounties::::get(0), 0); // Ensure parent-bounty curator received correctly reduced fee. - assert_eq!(Balances::free_balance(4), 101 + 6 - fee); // 101 + 6 - 2 - assert_eq!(Balances::reserved_balance(4), 0); + assert_eq!(Balances::free_balance(account_id(4)), 101 + 6 - fee); // 101 + 6 - 2 + assert_eq!(Balances::reserved_balance(account_id(4)), 0); // Verify parent-bounty beneficiary balance. - assert_eq!(Balances::free_balance(9), 34); - assert_eq!(Balances::reserved_balance(9), 0); + assert_eq!(Balances::free_balance(account_id(9)), 34); + assert_eq!(Balances::reserved_balance(account_id(9)), 0); }); } @@ -1266,7 +1441,7 @@ fn accept_curator_handles_different_deposit_calculations() { // in a different curator deposit, and if the child curator matches the parent curator. new_test_ext().execute_with(|| { // Setup a parent bounty. - let parent_curator = 0; + let parent_curator = account_id(0); let parent_index = 0; let parent_value = 1_000_000; let parent_fee = 10_000; @@ -1295,7 +1470,7 @@ fn accept_curator_handles_different_deposit_calculations() { // Case 1: Parent and child curator are not the same. let child_index = 0; - let child_curator = 1; + let child_curator = account_id(1); let child_value = 1_000; let child_fee = 100; let starting_balance = 100 * child_fee + child_value; @@ -1362,7 +1537,7 @@ fn accept_curator_handles_different_deposit_calculations() { // Case 3: Upper Limit let child_index = 2; - let child_curator = 2; + let child_curator = account_id(2); let child_value = 10_000; let child_fee = 5_000; @@ -1397,7 +1572,7 @@ fn accept_curator_handles_different_deposit_calculations() { // Case 4: Lower Limit let child_index = 3; - let child_curator = 3; + let child_curator = account_id(3); let child_value = 10_000; let child_fee = 0; From 56dd130f7edd43f053a9798dd0a51e794693ad39 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 5 Nov 2024 20:06:06 +0100 Subject: [PATCH 33/36] integrity test for account id derivation --- substrate/frame/child-bounties/src/lib.rs | 13 +++++++++++++ substrate/frame/child-bounties/src/tests.rs | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/substrate/frame/child-bounties/src/lib.rs b/substrate/frame/child-bounties/src/lib.rs index 2772148ef42d5..ea1d9547d4651 100644 --- a/substrate/frame/child-bounties/src/lib.rs +++ b/substrate/frame/child-bounties/src/lib.rs @@ -808,6 +808,19 @@ pub mod pallet { Ok(()) } } + + #[pallet::hooks] + impl Hooks> for Pallet { + fn integrity_test() { + let parent_bounty_id: BountyIndex = 1; + let child_bounty_id: BountyIndex = 2; + let _: T::AccountId = T::PalletId::get() + .try_into_sub_account(("cb", parent_bounty_id, child_bounty_id)) + .expect( + "The `AccountId` type must be large enough to fit the child bounty account ID.", + ); + } + } } impl Pallet { diff --git a/substrate/frame/child-bounties/src/tests.rs b/substrate/frame/child-bounties/src/tests.rs index 130fccf5888a8..939983054f667 100644 --- a/substrate/frame/child-bounties/src/tests.rs +++ b/substrate/frame/child-bounties/src/tests.rs @@ -1602,3 +1602,10 @@ fn accept_curator_handles_different_deposit_calculations() { assert_eq!(Balances::reserved_balance(child_curator), expected_deposit); }); } + +#[test] +fn integrity_test() { + new_test_ext().execute_with(|| { + ChildBounties::integrity_test(); + }); +} From d5f848fda9d638e3eb6e27c7e295e59e48d90e67 Mon Sep 17 00:00:00 2001 From: muharem Date: Tue, 5 Nov 2024 21:49:07 +0100 Subject: [PATCH 34/36] impl FromEntropy for U256 --- substrate/primitives/core/src/crypto.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index b04d94e2bf40d..cf24861e233c1 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -17,7 +17,7 @@ //! Cryptographic utilities. -use crate::{ed25519, sr25519}; +use crate::{ed25519, sr25519, U256}; use alloc::{format, str, vec::Vec}; #[cfg(all(not(feature = "std"), feature = "serde"))] use alloc::{string::String, vec}; @@ -1191,7 +1191,7 @@ macro_rules! impl_from_entropy_base { } } -impl_from_entropy_base!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128); +impl_from_entropy_base!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, U256); #[cfg(test)] mod tests { From 22d251eadb672da93135e538002cf141da957ff0 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 5 Nov 2024 23:11:35 +0100 Subject: [PATCH 35/36] Update prdoc Signed-off-by: Oliver Tale-Yazdi --- prdoc/pr_6255.prdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prdoc/pr_6255.prdoc b/prdoc/pr_6255.prdoc index 8b822940aac1c..c566a8f2aba7a 100644 --- a/prdoc/pr_6255.prdoc +++ b/prdoc/pr_6255.prdoc @@ -22,3 +22,5 @@ crates: bump: major - name: rococo-runtime bump: major +- name: sp-core + bump: minor From 46cd1ea703f828a9f6a7b855d7320f50b8858a2c Mon Sep 17 00:00:00 2001 From: muharem Date: Wed, 6 Nov 2024 01:32:56 +0100 Subject: [PATCH 36/36] update the prdoc --- prdoc/pr_6255.prdoc | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/prdoc/pr_6255.prdoc b/prdoc/pr_6255.prdoc index c566a8f2aba7a..7b69717b5c2d5 100644 --- a/prdoc/pr_6255.prdoc +++ b/prdoc/pr_6255.prdoc @@ -6,15 +6,23 @@ doc: child bounties from other parent bounties. This will allow for predictable indexes and the ability to batch creation and approval calls together. - - Introduces `ParentTotalChildBounties` storage item to keep the total child bounty count per + ### Migration for Runtime Pallet Instance + Use `migration::v1::MigrateToV1Impl` storage migration type to translate ids for the active + child bounties and migrate the state to the new schema. + + ### Migration for Clients + - Use new `ParentTotalChildBounties` storage item to iterate over child bounties for a certain parent bounty; - - Translates `ChildBounties` keys from (parent_id, old_child_id) to (parent_id, new_child_id); - - Replaces `ChildBountyDescriptions` storage item by new `ChildBountyDescriptionsV1` storage - item indexed by (parent_id, child_id) instead of (child_id); - - `V0ToV1ChildBountyIds` storage item provides the old_child_id -> parent_id, new_child_id - mapping; - - Deprecates `ChildBountyCount` storage item which will be removed in May 2025; - - Provides the migration from v0 to new v1 storage version. + - Use new `ChildBountyDescriptionsV1` storage item to get the bounty description instead of + removed `ChildBountyDescriptions`; + - Use `V0ToV1ChildBountyIds` storage item to look up the new child bounty id for a given + old child bounty id; + - Update the child bounty account id derivation from `PalletId + "cb" + child_id` to + `PalletId + "cb" + bounty_id + child_id`. + + ### Additional Notes + - The `ChildBountyCount` storage item is deprecated and will be remove in May 2025. + crates: - name: pallet-child-bounties bump: major