Remove use of OnInitialize, OnFinalize, ... traits in favor of Hooks#13577
Remove use of OnInitialize, OnFinalize, ... traits in favor of Hooks#13577vivekvpandya wants to merge 29 commits intoparitytech:masterfrom
Conversation
… contracts pallet
…t in grandpa pallet
|
@kianenigma could you please check if this is going in correct direction? |
|
You should use |
|
The CI pipeline was cancelled due to failure one of the required jobs. |
| 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> { |
There was a problem hiding this comment.
Why are we removing OnRuntimeUpgrade @kianenigma ?
I get the OnInitialize and OnFinalize, but OnRuntimeUpgrade is not really related to pallets.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Okay, so now this PR does not make sense, instead a PR is require that makes Hooks a super trait.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
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. |
|
This needs to be reworked based on #13577 (comment), can you still follow it @vivekvpandya? |
|
Yes I will take it further.
…On Fri, Apr 21, 2023, 7:42 PM Kian Paimani ***@***.***> wrote:
This needs to be reworked based on paritytech/substrate#13577 (comment)
<#13577 (comment)>,
can you still follow it @vivekvpandya <https://github.com/vivekvpandya>?
—
Reply to this email directly, view it on GitHub
<#13577 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABGZYBCJRBV2K7OAHZGGSK3XCKIWDANCNFSM6AAAAAAVWDNX6E>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
| <(COnRuntimeUpgrade, AllPalletsWithSystem) as OnRuntimeUpgrade>::on_runtime_upgrade() | ||
| <(COnRuntimeUpgrade, AllPalletsWithSystem) as frame_support::traits::Hooks< | ||
| System::BlockNumber, | ||
| >>::on_runtime_upgrade() |
There was a problem hiding this comment.
this is different than before because OnRuntimeUpgrade implementation is usually different than the hook implementation
|
I might be able to do this as a part of #14279. |
|
I tried to tackle this as a part of #14279 by making For example, 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 {} |
|
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. |
Fixes paritytech/polkadot-sdk#267