Skip to content

Commit

Permalink
Pallet AURA: remove pallet::getter macro and write the corresponding …
Browse files Browse the repository at this point in the history
…code (paritytech#3350)

Removed the `pallet::getter` macro call from storage type definitions
and added the corresponding implementations directly.
fixes paritytech#3330  

polkadot address: 14JzTPPUd8x8phKi8qLxHgNTnTMg6DUukCLXoWprejkaHXPz

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
  • Loading branch information
2 people authored and dharjeezy committed Mar 24, 2024
1 parent c02937c commit 933d857
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 30 deletions.
6 changes: 3 additions & 3 deletions cumulus/pallets/aura-ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ pub mod pallet {
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_finalize(_: BlockNumberFor<T>) {
// Update to the latest AuRa authorities.
Authorities::<T>::put(Aura::<T>::authorities());
Authorities::<T>::put(pallet_aura::Authorities::<T>::get());
}

fn on_initialize(_: BlockNumberFor<T>) -> Weight {
// Fetch the authorities once to get them into the storage proof of the PoV.
Authorities::<T>::get();

let new_slot = Aura::<T>::current_slot();
let new_slot = pallet_aura::CurrentSlot::<T>::get();

let (new_slot, authored) = match SlotInfo::<T>::get() {
Some((slot, authored)) if slot == new_slot => (slot, authored + 1),
Expand Down Expand Up @@ -116,7 +116,7 @@ pub mod pallet {
#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
let authorities = Aura::<T>::authorities();
let authorities = pallet_aura::Authorities::<T>::get();
Authorities::<T>::put(authorities);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
2 changes: 1 addition & 1 deletion cumulus/parachains/runtimes/starters/seedling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
2 changes: 1 addition & 1 deletion cumulus/parachains/runtimes/starters/shell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
2 changes: 1 addition & 1 deletion cumulus/parachains/runtimes/testing/penpal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
31 changes: 31 additions & 0 deletions prdoc/pr_3350.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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` from Pallet AURA

doc:
- audience: Runtime Dev
description: |
This PR removes all the declarations of macro `pallet::getter` in the Pallet AURA and replaces the use of storage getter functions authorities() & current_slot() with `StorageItem::get()` API across the crates as listed bellow.
The purpose is to discourage developers to use this macro, that is currently being removed and soon will be deprecated.

crates:
- name: pallet-aura
- name: solochain-template-runtime
- name: cumulus-pallet-aura-ext
- name: parachain-template-runtime
- name: people-westend-runtime
- name: people-rococo-runtime
- name: bridge-hub-rococo-runtime
- name: bridge-hub-westend-runtime
- name: rococo-parachain-runtime
- name: penpal-runtime
- name: glutton-westend-runtime
- name: shell-runtime
- name: seedling-runtime
- name: collectives-westend-runtime
- name: asset-hub-rococo-runtime
- name: asset-hub-westend-runtime
- name: contracts-rococo-runtime
- name: coretime-westend-runtime
- name: coretime-rococo-runtime
12 changes: 5 additions & 7 deletions substrate/frame/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,14 @@ pub mod pallet {

/// The current authority set.
#[pallet::storage]
#[pallet::getter(fn authorities)]
pub(super) type Authorities<T: Config> =
pub type Authorities<T: Config> =
StorageValue<_, BoundedVec<T::AuthorityId, T::MaxAuthorities>, ValueQuery>;

/// The current slot of this block.
///
/// This will be set in `on_initialize`.
#[pallet::storage]
#[pallet::getter(fn current_slot)]
pub(super) type CurrentSlot<T: Config> = StorageValue<_, Slot, ValueQuery>;
pub type CurrentSlot<T: Config> = StorageValue<_, Slot, ValueQuery>;

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
Expand Down Expand Up @@ -318,7 +316,7 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
// instant changes
if changed {
let next_authorities = validators.map(|(_, k)| k).collect::<Vec<_>>();
let last_authorities = Self::authorities();
let last_authorities = Authorities::<T>::get();
if last_authorities != next_authorities {
if next_authorities.len() as u32 > T::MaxAuthorities::get() {
log::warn!(
Expand Down Expand Up @@ -374,7 +372,7 @@ impl<T: Config, Inner: FindAuthor<u32>> FindAuthor<T::AuthorityId>
{
let i = Inner::find_author(digests)?;

let validators = <Pallet<T>>::authorities();
let validators = Authorities::<T>::get();
validators.get(i as usize).cloned()
}
}
Expand All @@ -384,7 +382,7 @@ pub type AuraAuthorId<T> = FindAccountFromAuthorIndex<T, Pallet<T>>;

impl<T: Config> IsMember<T::AuthorityId> for Pallet<T> {
fn is_member(authority_id: &T::AuthorityId) -> bool {
Self::authorities().iter().any(|id| id == authority_id)
Authorities::<T>::get().iter().any(|id| id == authority_id)
}
}

Expand Down
7 changes: 4 additions & 3 deletions substrate/frame/aura/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

#![cfg(test)]

use crate::mock::{build_ext_and_execute_test, Aura, MockDisabledValidators, System};
use super::pallet;
use crate::mock::{build_ext_and_execute_test, Aura, MockDisabledValidators, System, Test};
use codec::Encode;
use frame_support::traits::OnInitialize;
use sp_consensus_aura::{Slot, AURA_ENGINE_ID};
Expand All @@ -28,8 +29,8 @@ use sp_runtime::{Digest, DigestItem};
#[test]
fn initial_values() {
build_ext_and_execute_test(vec![0, 1, 2, 3], || {
assert_eq!(Aura::current_slot(), 0u64);
assert_eq!(Aura::authorities().len(), Aura::authorities_len());
assert_eq!(pallet::CurrentSlot::<Test>::get(), 0u64);
assert_eq!(pallet::Authorities::<Test>::get().len(), Aura::authorities_len());
assert_eq!(Aura::authorities_len(), 4);
});
}
Expand Down
4 changes: 3 additions & 1 deletion templates/parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};

use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};

use pallet_aura::Authorities;

// XCM Imports
use xcm::latest::prelude::BodyId;

Expand Down Expand Up @@ -547,7 +549,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
Authorities::<Runtime>::get().into_inner()
}
}

Expand Down
2 changes: 1 addition & 1 deletion templates/solochain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl_runtime_apis! {
}

fn authorities() -> Vec<AuraId> {
Aura::authorities().into_inner()
pallet_aura::Authorities::<Runtime>::get().into_inner()
}
}

Expand Down

0 comments on commit 933d857

Please sign in to comment.