Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pallet AURA: remove pallet::getter macro and write the corresponding code #3350

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7b95a13
remove pallet::getter macro and write the corresponding code
k-gunjan Feb 16, 2024
9d3c70d
replaced call to fun authorities() with ::get() API
k-gunjan Feb 16, 2024
3d08424
removed authorities and current_slot calls from pallet_aura
k-gunjan Feb 24, 2024
b3da689
refactor node-template-runtime
k-gunjan Feb 24, 2024
bbc09f7
resolve conflict
k-gunjan Mar 5, 2024
64d947e
refactor parachain template
k-gunjan Mar 5, 2024
70f9ded
refactor people-westend runtime
k-gunjan Mar 5, 2024
6dbffeb
refactor people rococo runtime
k-gunjan Mar 5, 2024
9e13097
refactor bridge-hub-rococo-runtime
k-gunjan Mar 5, 2024
e42fee4
refactor bridge-hub-westend-runtime
k-gunjan Mar 5, 2024
ec3602e
rococo-parachain-runtime
k-gunjan Mar 5, 2024
83e1693
refactor penpal runtime
k-gunjan Mar 5, 2024
f217fff
glutton-westend-runtime
k-gunjan Mar 5, 2024
b87d23a
refactor shell runtime
k-gunjan Mar 5, 2024
8cd5fab
refactor seedling runtime
k-gunjan Mar 5, 2024
e517dce
collectives-westend-runtime
k-gunjan Mar 5, 2024
20be756
refactor asset-hub-rococo-runtime
k-gunjan Mar 5, 2024
a9ded7b
refactor asset-hub-westend-runtime
k-gunjan Mar 5, 2024
0e939c1
refactor contracts-rococo-runtime
k-gunjan Mar 5, 2024
f554e68
refactor coretime westend
k-gunjan Mar 5, 2024
d753aa2
refactor coretime rococo
k-gunjan Mar 5, 2024
9b59665
refactor to match master branch
k-gunjan Mar 6, 2024
930e4c7
prdoc for #3350
k-gunjan Mar 15, 2024
1eb4bea
Merge branch 'master' into gunjan-remove-getter-macro-pallet-aura-iss…
k-gunjan Mar 15, 2024
0008aca
Apply suggestions from code review
bkchr Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1071,7 +1071,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 @@ -1102,7 +1102,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 @@ -794,7 +794,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 @@ -544,7 +544,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 @@ -781,7 +781,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 @@ -444,7 +444,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 @@ -499,7 +499,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 @@ -490,7 +490,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 @@ -357,7 +357,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 @@ -473,7 +473,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 @@ -473,7 +473,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 @@ -287,7 +287,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 @@ -344,7 +344,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 @@ -689,7 +689,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 @@ -762,7 +762,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 @@ -168,16 +168,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 @@ -335,7 +333,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 @@ -391,7 +389,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 @@ -401,7 +399,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 @@ -548,7 +550,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 @@ -417,7 +417,7 @@ impl_runtime_apis! {
}

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

Expand Down
Loading