Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Remove use of OnInitialize, OnFinalize, ... traits in favor of Hooks#13577

Closed
vivekvpandya wants to merge 29 commits intoparitytech:masterfrom
vivekvpandya:vivek-issue-11925
Closed

Remove use of OnInitialize, OnFinalize, ... traits in favor of Hooks#13577
vivekvpandya wants to merge 29 commits intoparitytech:masterfrom
vivekvpandya:vivek-issue-11925

Conversation

@vivekvpandya
Copy link
Contributor

@vivekvpandya
Copy link
Contributor Author

@kianenigma could you please check if this is going in correct direction?
There are few more changes required , specially in executive pallet, but before I invest more time I want your glance on this.
🙏

@kianenigma
Copy link
Contributor

You should use AllPallets: Hooks in `Executive as well.

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: cargo-check-benches
Logs: https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/2542622

pub struct Migration<T, I = ()>(PhantomData<(T, I)>);

impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for Migration<T, I> {
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Migration<T, I> {
Copy link
Member

@ggwpez ggwpez Mar 18, 2023

Choose a reason for hiding this comment

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

Why are we removing OnRuntimeUpgrade @kianenigma ?
I get the OnInitialize and OnFinalize, but OnRuntimeUpgrade is not really related to pallets.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe Hooks should have never copied all the trait methods. Instead it should have been a trait that collects all the important traits as super traits.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think @bkchr's suggestion makes the right sense here, Hooks should be a mere supertrait, and we can then keep the old traits for when a fine-grained specification is needed, such as the case of OnRuntimeUpgrade.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, so now this PR does not make sense, instead a PR is require that makes Hooks a super trait.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kianenigma @bkchr could you please explain following:
if we make Hooks a super trait then what is the point of having it?
AFAIU all pallets needs to implement old traits and Hooks does not add anything on top of what individual traits like OnInitialize ... adds.
Kindly correct me if my understanding is wrong here.

Copy link
Contributor

Choose a reason for hiding this comment

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

It wouldn't add any functionality in itself, and it would just be a marker trait. Its main purpose would be that inside the pallet macros you would only implement Hooks and not 5 or 6 different traits.

Copy link
Contributor

@gui1117 gui1117 May 27, 2023

Choose a reason for hiding this comment

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

In the past the pallet macro was adding a bit more than just logging when implementing OnRuntimeUpgrade trait.

So it felt a bit abusive to add code in the implementation of the Hooks::on_runtime_upgrade function block.
The idea was to add as less magic as possible inside the code that is written by the user. Generally pallet macro don't modify their code at all just use it to implement more traits and types.

Now that the only added logic is logging and span it can be ok.
But still when user call this Hooks::on_runtime_upgrade function in the tests or anywhere it could be confusing to see more logging and span than expected.

Also it means that in the future if more code needs to be added by the pallet macro then what the user see and what the implementation do will differ again.

@stale
Copy link

stale bot commented Apr 19, 2023

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added A3-stale and removed A3-stale labels Apr 19, 2023
@kianenigma
Copy link
Contributor

This needs to be reworked based on #13577 (comment), can you still follow it @vivekvpandya?

@vivekvpandya
Copy link
Contributor Author

vivekvpandya commented Apr 21, 2023 via email

<(COnRuntimeUpgrade, AllPalletsWithSystem) as OnRuntimeUpgrade>::on_runtime_upgrade()
<(COnRuntimeUpgrade, AllPalletsWithSystem) as frame_support::traits::Hooks<
System::BlockNumber,
>>::on_runtime_upgrade()
Copy link
Contributor

Choose a reason for hiding this comment

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

this is different than before because OnRuntimeUpgrade implementation is usually different than the hook implementation

@kianenigma
Copy link
Contributor

I might be able to do this as a part of #14279.

@kianenigma
Copy link
Contributor

kianenigma commented Jun 19, 2023

I tried to tackle this as a part of #14279 by making Hooks be just a marker trait and the current issue I faced is that some of the feature gated functions related to try-runtime will no longer quite work as-is.

For example, TryState is not even available outside of feature=try-state. In order to make a supertrait Hooks work, first TryState needs to be pulled out of feature=try-state and be available at all times. It can be an empty trait in not(feature=try-state).

Something like

#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))]
#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))]
#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))]
pub trait Hooks<BlockNumber: Clone + Copy + AtLeast32BitUnsigned>:
	OnInitialize<BlockNumber>
	+ Poll<BlockNumber>
	+ OnFinalize<BlockNumber>
	+ OnIdle<BlockNumber>
	+ OnRuntimeUpgrade
	+ super::OffchainWorker<BlockNumber>
	+ IntegrityTest
	+ TryState
{
}

#[cfg(not(feature = "try-runtime"))]
#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))]
#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))]
#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))]
pub trait TryState {}

@stale
Copy link

stale bot commented Jul 19, 2023

Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the A3-stale label Jul 19, 2023
@stale stale bot closed this Aug 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Deprecation] Deprecate individual hooks traits like OnInitialize

6 participants