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

Removed pallet::getter from pallet-election-provider-multi-block #7932

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions prdoc/pr_7932.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: Removed pallet::getter from pallet-election-provider-multi-block
doc:
- audience: Runtime Dev
description: |
This pr removes all pallet::getter occurrences from pallet-election-provider-multi-block, replacing them with explicit implementations.

crates:
- name: pallet-election-provider-multi-block
bump: patch
12 changes: 10 additions & 2 deletions substrate/frame/election-provider-multi-block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,10 @@ pub mod pallet {
///
/// This is merely incremented once per every time that an upstream `elect` is called.
#[pallet::storage]
#[pallet::getter(fn round)]
pub type Round<T: Config> = StorageValue<_, u32, ValueQuery>;

/// Current phase.
#[pallet::storage]
#[pallet::getter(fn current_phase)]
pub type CurrentPhase<T: Config> = StorageValue<_, Phase<BlockNumberFor<T>>, ValueQuery>;

/// Wrapper struct for working with snapshots.
Expand Down Expand Up @@ -1009,6 +1007,16 @@ pub mod pallet {
}

impl<T: Config> Pallet<T> {
/// Internal counter for the number of rounds.
pub fn round() -> u32 {
Round::<T>::get()
}

/// Current phase.
pub fn current_phase() -> Phase<BlockNumberFor<T>> {
CurrentPhase::<T>::get()
}

/// Returns the most significant page of the snapshot.
///
/// Based on the contract of `ElectionDataProvider`, this is the first page that is filled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,10 @@ pub(crate) mod pallet {

/// The minimum score that each solution must attain in order to be considered feasible.
#[pallet::storage]
#[pallet::getter(fn minimum_score)]
pub(crate) type MinimumScore<T: Config> = StorageValue<_, ElectionScore>;

/// Storage item for [`Status`].
#[pallet::storage]
#[pallet::getter(fn status_storage)]
pub(crate) type StatusStorage<T: Config> = StorageValue<_, Status, ValueQuery>;

#[pallet::pallet]
Expand Down Expand Up @@ -552,6 +550,16 @@ pub(crate) mod pallet {
}

impl<T: Config> Pallet<T> {
/// The minimum score that each solution must attain in order to be considered feasible.
pub fn minimum_score() -> Option<ElectionScore> {
MinimumScore::<T>::get()
}

/// Storage item for `Status`.
pub fn status_storage() -> Status {
StatusStorage::<T>::get()
}

fn do_on_initialize() -> Weight {
if let Status::Ongoing(current_page) = Self::status_storage() {
let maybe_page_solution =
Expand Down
Loading