From 494a4a7ffbb6facfa1bdd742c0f3216086c25478 Mon Sep 17 00:00:00 2001 From: "polka.dom" Date: Wed, 19 Jun 2024 13:33:47 -0400 Subject: [PATCH 1/8] To turbo --- .../insecure-randomness-collective-flip/README.md | 2 +- .../insecure-randomness-collective-flip/src/lib.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/substrate/frame/insecure-randomness-collective-flip/README.md b/substrate/frame/insecure-randomness-collective-flip/README.md index 4f02782fa659..fc38367bf552 100644 --- a/substrate/frame/insecure-randomness-collective-flip/README.md +++ b/substrate/frame/insecure-randomness-collective-flip/README.md @@ -44,7 +44,7 @@ pub mod pallet { impl Pallet { #[pallet::weight(0)] pub fn random_module_example(origin: OriginFor) -> DispatchResult { - let _random_value = >::random(&b"my context"[..]); + let _random_value = pallet_insecure_randomness_collective_flip::Pallet::::random(&b"my context"[..]); Ok(()) } } diff --git a/substrate/frame/insecure-randomness-collective-flip/src/lib.rs b/substrate/frame/insecure-randomness-collective-flip/src/lib.rs index bdb089a14200..724da696a081 100644 --- a/substrate/frame/insecure-randomness-collective-flip/src/lib.rs +++ b/substrate/frame/insecure-randomness-collective-flip/src/lib.rs @@ -60,7 +60,7 @@ //! impl Pallet { //! #[pallet::weight(0)] //! pub fn random_module_example(origin: OriginFor) -> DispatchResult { -//! let _random_value = >::random(&b"my context"[..]); +//! let _random_value = pallet_insecure_randomness_collective_flip::Pallet::::random(&b"my context"[..]); //! Ok(()) //! } //! } @@ -101,9 +101,9 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(block_number: BlockNumberFor) -> Weight { - let parent_hash = >::parent_hash(); + let parent_hash = frame_system::Pallet::::parent_hash(); - >::mutate(|ref mut values| { + RandomMaterial::::mutate(|ref mut values| { if values.try_push(parent_hash).is_err() { let index = block_number_to_index::(block_number); values[index] = parent_hash; @@ -135,10 +135,10 @@ impl Randomness> for Pallet { /// and mean that all bits of the resulting value are entirely manipulatable by the author of /// the parent block, who can determine the value of `parent_hash`. fn random(subject: &[u8]) -> (T::Hash, BlockNumberFor) { - let block_number = >::block_number(); + let block_number = frame_system::Pallet::::block_number(); let index = block_number_to_index::(block_number); - let hash_series = >::get(); + let hash_series = RandomMaterial::::get(); let seed = if !hash_series.is_empty() { // Always the case after block 1 is initialized. hash_series From 8017ea1bf911141c5f08ed79080f3ff327d8a285 Mon Sep 17 00:00:00 2001 From: "polka.dom" Date: Wed, 19 Jun 2024 13:34:49 -0400 Subject: [PATCH 2/8] Create prdoc --- prdoc/pr_9999.prdoc | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 prdoc/pr_9999.prdoc diff --git a/prdoc/pr_9999.prdoc b/prdoc/pr_9999.prdoc new file mode 100644 index 000000000000..03a458876dfa --- /dev/null +++ b/prdoc/pr_9999.prdoc @@ -0,0 +1,11 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: ... + +doc: + - audience: ... + description: | + ... + +crates: [ ] From ea14112381ce56deac2d5060b1c69d4f3e83f8a1 Mon Sep 17 00:00:00 2001 From: "polka.dom" Date: Wed, 19 Jun 2024 13:36:47 -0400 Subject: [PATCH 3/8] Fill out prdoc --- prdoc/pr_9999.prdoc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/prdoc/pr_9999.prdoc b/prdoc/pr_9999.prdoc index 03a458876dfa..84c8e3e4b8df 100644 --- a/prdoc/pr_9999.prdoc +++ b/prdoc/pr_9999.prdoc @@ -1,11 +1,14 @@ # Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 # See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json -title: ... +title: Removed `pallet::getter` usage from pallet-insecure-randomness-collective-flip doc: - - audience: ... + - audience: Runtime Dev description: | - ... + This PR removed the `pallet::getter`s from `pallet-insecure-randomness-collective-flip`. + The syntax `StorageItem::::get()` should be used instead. -crates: [ ] +crates: + - name: pallet-insecure-randomness-collective-flip + bump: major From 11f0fd8e870c9019d91034822b8045c9468347ee Mon Sep 17 00:00:00 2001 From: "polka.dom" Date: Wed, 19 Jun 2024 13:42:49 -0400 Subject: [PATCH 4/8] Remove random_material getter --- .../insecure-randomness-collective-flip/src/lib.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/substrate/frame/insecure-randomness-collective-flip/src/lib.rs b/substrate/frame/insecure-randomness-collective-flip/src/lib.rs index 724da696a081..7739591827cd 100644 --- a/substrate/frame/insecure-randomness-collective-flip/src/lib.rs +++ b/substrate/frame/insecure-randomness-collective-flip/src/lib.rs @@ -118,8 +118,7 @@ pub mod pallet { /// is arranged as a ring buffer with `block_number % 81` being the index into the `Vec` of /// the oldest hash. #[pallet::storage] - #[pallet::getter(fn random_material)] - pub(super) type RandomMaterial = + pub type RandomMaterial = StorageValue<_, BoundedVec>, ValueQuery>; } @@ -226,7 +225,7 @@ mod tests { setup_blocks(38); - let random_material = CollectiveFlip::random_material(); + let random_material = RandomMaterial::::get(); assert_eq!(random_material.len(), 38); assert_eq!(random_material[0], genesis_hash); @@ -240,7 +239,7 @@ mod tests { setup_blocks(81); - let random_material = CollectiveFlip::random_material(); + let random_material = RandomMaterial::::get(); assert_eq!(random_material.len(), 81); assert_ne!(random_material[0], random_material[1]); @@ -255,7 +254,7 @@ mod tests { setup_blocks(162); - let random_material = CollectiveFlip::random_material(); + let random_material = RandomMaterial::::get(); assert_eq!(random_material.len(), 81); assert_ne!(random_material[0], random_material[1]); @@ -276,7 +275,7 @@ mod tests { assert_eq!(known_since, 162 - RANDOM_MATERIAL_LEN as u64); assert_ne!(random, H256::zero()); - assert!(!CollectiveFlip::random_material().contains(&random)); + assert!(!RandomMaterial::::get().contains(&random)); }); } } From ec1f9d7be7ae8990e3791a6ec57beac47d31be34 Mon Sep 17 00:00:00 2001 From: "polka.dom" Date: Wed, 19 Jun 2024 15:15:05 -0400 Subject: [PATCH 5/8] Update prdoc number --- prdoc/{pr_9999.prdoc => pr_4839.prdoc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename prdoc/{pr_9999.prdoc => pr_4839.prdoc} (100%) diff --git a/prdoc/pr_9999.prdoc b/prdoc/pr_4839.prdoc similarity index 100% rename from prdoc/pr_9999.prdoc rename to prdoc/pr_4839.prdoc From cb4bc8ef0c7f7ebd05b89d4ef03dabb7302c5d71 Mon Sep 17 00:00:00 2001 From: "polka.dom" Date: Sat, 22 Jun 2024 14:07:14 -0400 Subject: [PATCH 6/8] Implement missing getter --- .../frame/insecure-randomness-collective-flip/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/substrate/frame/insecure-randomness-collective-flip/src/lib.rs b/substrate/frame/insecure-randomness-collective-flip/src/lib.rs index 7739591827cd..b605b4d08582 100644 --- a/substrate/frame/insecure-randomness-collective-flip/src/lib.rs +++ b/substrate/frame/insecure-randomness-collective-flip/src/lib.rs @@ -120,6 +120,13 @@ pub mod pallet { #[pallet::storage] pub type RandomMaterial = StorageValue<_, BoundedVec>, ValueQuery>; + + impl Pallet { + /// Gets the random material storage value + pub fn random_material() -> BoundedVec> { + RandomMaterial::::get() + } + } } impl Randomness> for Pallet { From 44d17f1f75622fb4128368a9f6dc0102b427dc23 Mon Sep 17 00:00:00 2001 From: "polka.dom" Date: Sat, 22 Jun 2024 14:08:12 -0400 Subject: [PATCH 7/8] Switch semver bump to minor --- prdoc/pr_4839.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_4839.prdoc b/prdoc/pr_4839.prdoc index 84c8e3e4b8df..1cd778f0a97f 100644 --- a/prdoc/pr_4839.prdoc +++ b/prdoc/pr_4839.prdoc @@ -11,4 +11,4 @@ doc: crates: - name: pallet-insecure-randomness-collective-flip - bump: major + bump: minor From 1c1c39e3354c88cc0f1d211188b4791aaaa762d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Wed, 3 Jul 2024 22:26:59 +0200 Subject: [PATCH 8/8] Update prdoc/pr_4839.prdoc Co-authored-by: Oliver Tale-Yazdi --- prdoc/pr_4839.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_4839.prdoc b/prdoc/pr_4839.prdoc index 1cd778f0a97f..84bb393d4c45 100644 --- a/prdoc/pr_4839.prdoc +++ b/prdoc/pr_4839.prdoc @@ -11,4 +11,4 @@ doc: crates: - name: pallet-insecure-randomness-collective-flip - bump: minor + bump: patch