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

Remove usage of the pallet::getter macro from pallet-grandpa #4529

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

PolkadotDom
Copy link
Contributor

@PolkadotDom PolkadotDom commented May 20, 2024

As per #3326, removes pallet::getter macro usage from pallet-grandpa. The syntax StorageItem::<T, I>::get() should be used instead.

cc @muraca

@@ -430,6 +424,54 @@ pub enum StoredState<N> {
}

impl<T: Config> Pallet<T> {
/// Get the tate of the current authority set
pub fn state() -> StoredState<BlockNumberFor<T>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you started to add them here now?

Copy link
Member

@davxy davxy May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Furthermore, if you absolutely need these accessors, each of them can be simplified. E.g.

pub fn state() -> StoredState<BlockNumberFor<T>> {
    State::<T>::get()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good call on the simplification, I had just replaced them with what the macro generated. Will fix 👍

And I've added the explicit getters because the getter macro made the storage values read only outside the crate (since they're pub(super)), so taking the macro away reduced their visibility to other pallets. Usually this isn't an issue because most the storage values are pub, but I opted not to switch to pub because I feel preserving data authority is important, especially since I don't know the reasoning behind why they were made read-only originally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no real reasoning and anyone could write them by just writing to the storage items. So, just make the storage items public.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll fix and subsequently do this moving forward.

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: cargo-clippy
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6273292

@PolkadotDom PolkadotDom requested review from bkchr and davxy June 22, 2024 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants