-
Notifications
You must be signed in to change notification settings - Fork 814
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
Update Scheduler to have a configurable block provider #7434 #7441
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Direction is good
substrate/frame/scheduler/src/lib.rs
Outdated
@@ -297,6 +300,8 @@ pub mod pallet { | |||
#[pallet::storage] | |||
pub type IncompleteSince<T: Config> = StorageValue<_, BlockNumberFor<T>>; | |||
|
|||
type BlockNumberProvider: BlockNumberProvider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need a doc comment that explains this type, and warns that it must not be too much out of sync with the local block number. More precisely between every block the increment of this number should be reasonably small otherwise performance degrades will degrade a lot as it reads one storage per block number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I will add it towards the end of the pr for sure, I will look into it. At this moment, I am not entirely sure of the value that needs to be advised, i will get more insights into it, thanks for the reminder :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can suggest people to use the system block number or the relay chain block number (this second option, only if they expect their parachain to execute very regularly).
note: this is a part of #6297 |
This is where I am stuck atm:
What I have tried:
Now this, makes me think I have 2 following options going ahead:
Would like to get some opinion/help here on the options, or if there is any another thing to try Note: things I have tried are just a summary of the rabbit hole,if you do leave a comment here, I can try it out and answer if it works for me or not |
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
The type: <<T as frame_system::Config>::Block as sp_runtime::traits::Block>::Header as sp_runtime::traits::Header>::Number Doesn't implement: EncodeLike<<<T as pallet::Config>::BlockNumberProvider as sp_runtime::traits::BlockNumberProvider>::BlockNumber> Because: <<T as pallet::Config>::BlockNumberProvider as sp_runtime::traits::BlockNumberProvider>::BlockNumber Is a completely different type. I think you are trying somewhere to put the system block number into storage, but the type expect the configured provided block number. |
Looking at the current failure it fails when running:
and other similar. I tried:
|
Reverted the last commit, as it did not really solve much, bringing it to attention of @gui1117 @ggwpez #7441 (comment) -> read the comment here |
@seemantaggarwal should be your new block number alias instead
|
Requesting review from @gui1117 @muharem @ggwpez @kianenigma |
@@ -292,6 +294,8 @@ pub mod pallet { | |||
|
|||
/// The preimage provider with which we look up call hashes to get the call. | |||
type Preimages: QueryPreimage<H = Self::Hashing> + StorePreimage; | |||
|
|||
type BlockNumberProvider: BlockNumberProvider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs? Devs using this pallet wont know what it is or how it should be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in commit 03fc0da
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check how we normally write these docs. This is a comment //
instead of a rust doc.
Also there should be one introduction sentence on what it does and then more elaborate paragraph following.
Just put yourself into the position of someone having never seen this before. What is it? How am i supposed to use it? And possible implications.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in commit -> d7a8db1
open question, I did try and put myself into the shoes for somebody new (was relatively easy, did not require any roleplaying haha) and I think this should be maybe a part of a larger readme? Not just for this pallet, but over multiple pallets explaining this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Runtime will implement the config trait they usually want documentation as precise as possible.
I agree crate documentation is also good, and in this PR case we can warn in both the crate doc and the config doc.
prdoc/pr_7441.prdoc
Outdated
description: |- | ||
Follow up from https://github.com/paritytech/polkadot-sdk/pull/6362#issuecomment-2629744365 | ||
|
||
The goal of this PR is to have the treasury pallet work on a parachain which does not produce blocks on a regular schedule, thus can use the relay chain as a block provider. Because blocks are not produced regularly, we cannot make the assumption that block number increases monotonically, and thus have new logic to handle multiple spend periods passing between blocks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and thus have new logic to handle multiple spend periods passing between blocks
I think this is also dated?
prdoc/pr_7441.prdoc
Outdated
|
||
Requirement: | ||
|
||
instead of using the hard coded system block number. We add an associated type BlockNumberProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prdoc is meant for the external world. It must explain how to integrate the new change. Putting requirements here will not be so helpful for someone checking this 😄
@@ -292,6 +294,8 @@ pub mod pallet { | |||
|
|||
/// The preimage provider with which we look up call hashes to get the call. | |||
type Preimages: QueryPreimage<H = Self::Hashing> + StorePreimage; | |||
|
|||
type BlockNumberProvider: BlockNumberProvider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check how we normally write these docs. This is a comment //
instead of a rust doc.
Also there should be one introduction sentence on what it does and then more elaborate paragraph following.
Just put yourself into the position of someone having never seen this before. What is it? How am i supposed to use it? And possible implications.
prdoc/pr_7441.prdoc
Outdated
Follow up from https://github.com/paritytech/polkadot-sdk/pull/6362#issuecomment-2629744365 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up from https://github.com/paritytech/polkadot-sdk/pull/6362#issuecomment-2629744365 |
we do not really need it in prdoc
prdoc/pr_7441.prdoc
Outdated
description: |- | ||
Follow up from https://github.com/paritytech/polkadot-sdk/pull/6362#issuecomment-2629744365 | ||
|
||
This PR modifies the pallet_scheduler to support parachains that do not produce blocks on a regular schedule. Since block numbers may not increase monotonically in such environments, the scheduler cannot rely on frame_system::Pallet::<T>::block_number(). Instead, this update introduces BlockNumberProvider = frame_system::Pallet<Runtime> in pallet_scheduler::Config, allowing the scheduler to use an external provider, such as the relay chain, for block numbers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is misleading. It make block number provider configurable. It can be any source, for any type of chain (not only parachain). There is no problem keeping the schduler on parachains system block provider as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also mention that to keep the behaviour as it used to be before this config introduced, they need to set it frame_system::Pallet::<Runtime>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read the issue and the comments carefully I already mentioned this
substrate/frame/scheduler/src/lib.rs
Outdated
/// Execute the scheduled calls | ||
fn on_initialize(now: BlockNumberFor<T>) -> Weight { | ||
fn on_initialize(_do_not_use_local_block_number: SystemBlockNumberFor<T>) -> Weight { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn on_initialize(_do_not_use_local_block_number: SystemBlockNumberFor<T>) -> Weight { | |
fn on_initialize(_n: SystemBlockNumberFor<T>) -> Weight { |
why? using local block provider can be just ok
@@ -1636,6 +1636,7 @@ fn on_initialize_weight_is_correct() { | |||
)); | |||
|
|||
// Will include the named periodic only | |||
System::set_block_number(1); | |||
assert_eq!( | |||
Scheduler::on_initialize(1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scheduler::on_initialize(1), | |
Scheduler::on_initialize(0), |
I would make it everywhere like this to highlight it has not effect, plus a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks, I need to start it by 0 instead of 1, and just add a comment, that this should not make a difference to the working? I did not understand what is the comment I need to put
substrate/frame/scheduler/src/lib.rs
Outdated
@@ -926,11 +934,11 @@ impl<T: Config> Pallet<T> { | |||
let mut agenda = Agenda::<T>::get(when); | |||
let index = if (agenda.len() as u32) < T::MaxScheduledPerBlock::get() { | |||
// will always succeed due to the above check. | |||
let _ = agenda.try_push(Some(what)); | |||
let _ = agenda.try_push(Some(what.clone())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why clone? please review your code before requesting others to review
substrate/frame/scheduler/src/lib.rs
Outdated
/// Suggested value: Use the system block number or if you expect the parachain to execute | ||
/// very regularly you can use the relay chain block number. Warning: This value must not | ||
/// be too much out of sync with the local block number. Between every block the increment of | ||
/// this number should be reasonably small to avoid performance degradation and added latency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doc needs to be updated. not clear, not right, not rust style.
what is "very regularly"? what is "much out of sync"? "he increment of this number should be reasonably small", the increment is +1
. but overall you need to rewrite it, wrong direction.
All GitHub workflows were cancelled due to failure one of the required jobs. |
Follow up from #6362 (comment)
The goal of this PR is to have the scheduler pallet work on a parachain which does not produce blocks on a regular schedule, thus can use the relay chain as a block provider.
Because blocks are not produced regularly, we cannot make the assumption that block number increases monotonically, and thus have new logic to handle multiple spend periods passing between blocks.
Requirement:
instead of using the hard coded system block number. We add an associated type BlockNumberProvider