diff --git a/prdoc/pr_4839.prdoc b/prdoc/pr_4839.prdoc new file mode 100644 index 000000000000..84bb393d4c45 --- /dev/null +++ b/prdoc/pr_4839.prdoc @@ -0,0 +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: Removed `pallet::getter` usage from pallet-insecure-randomness-collective-flip + +doc: + - 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: + - name: pallet-insecure-randomness-collective-flip + bump: patch 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..b605b4d08582 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; @@ -118,9 +118,15 @@ 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>; + + impl Pallet { + /// Gets the random material storage value + pub fn random_material() -> BoundedVec> { + RandomMaterial::::get() + } + } } impl Randomness> for Pallet { @@ -135,10 +141,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 @@ -226,7 +232,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 +246,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 +261,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 +282,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)); }); } }