-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix for Issue 4762 #4803
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
Merged
+80
−45
Merged
Fix for Issue 4762 #4803
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8973908
Fix issue 4762
gotnoshoeson c39556e
Ready for PR
gotnoshoeson 05197d1
Update inline docs
gotnoshoeson 43add5d
Updates per code review
gotnoshoeson d3e03ff
Add more notes per review
gotnoshoeson 71d8171
Merge branch 'master' into issue-4762
bkchr 8264ab8
Add prdoc
gotnoshoeson 1a04152
Merge branch 'master' into issue-4762
bkchr 6bbf1a3
Apply suggestions from code review
bkchr b3551d6
Fix issues
bkchr 2927182
Merge branch 'master' into issue-4762
bkchr eaba016
Update prdoc/pr_4803.prdoc
bkchr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -646,7 +646,7 @@ pub mod pallet { | |
| impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> { | ||
| fn on_initialize(_n: BlockNumberFor<T>) -> Weight { | ||
| if let Some(weight_limit) = T::ServiceWeight::get() { | ||
| Self::service_queues(weight_limit) | ||
| Self::service_queues(weight_limit, ServiceQueuesContext::OnInitialize) | ||
| } else { | ||
| Weight::zero() | ||
| } | ||
|
|
@@ -655,7 +655,7 @@ pub mod pallet { | |
| fn on_idle(_n: BlockNumberFor<T>, remaining_weight: Weight) -> Weight { | ||
| if let Some(weight_limit) = T::IdleMaxServiceWeight::get() { | ||
| // Make use of the remaining weight to process enqueued messages. | ||
| Self::service_queues(weight_limit.min(remaining_weight)) | ||
| Self::service_queues(weight_limit.min(remaining_weight), ServiceQueuesContext::OnIdle) | ||
| } else { | ||
| Weight::zero() | ||
| } | ||
|
|
@@ -774,6 +774,16 @@ enum MessageExecutionStatus { | |
| StackLimitReached, | ||
| } | ||
|
|
||
| /// The context to pass to service_queues through on_idle and on_initialize hooks | ||
| /// We don't want to throw the defensive message if called from on_idle hook | ||
| #[derive(PartialEq)] | ||
| enum ServiceQueuesContext { | ||
| /// Context of on_idle hook | ||
| OnIdle, | ||
| /// Context of on_initialize hook | ||
| OnInitialize, | ||
| } | ||
|
|
||
| impl<T: Config> Pallet<T> { | ||
| /// Knit `origin` into the ready ring right at the end. | ||
| /// | ||
|
|
@@ -1554,12 +1564,16 @@ impl<T: Get<O>, O: Into<u32>> Get<u32> for IntoU32<T, O> { | |
| impl<T: Config> ServiceQueues for Pallet<T> { | ||
| type OverweightMessageAddress = (MessageOriginOf<T>, PageIndex, T::Size); | ||
|
|
||
| fn service_queues(weight_limit: Weight) -> Weight { | ||
| fn service_queues(weight_limit: Weight, context: ServiceQueuesContext) -> Weight { | ||
| let mut weight = WeightMeter::with_limit(weight_limit); | ||
|
|
||
| // Get the maximum weight that processing a single message may take: | ||
| let max_weight = Self::max_message_weight(weight_limit).unwrap_or_else(|| { | ||
| defensive!("Not enough weight to service a single message."); | ||
| // throw defensive message when service_queues is called from on_initialize | ||
| // don't throw message when service_queues is called from on_idle | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add the reason here, that it doesn't matter if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, that makes sense. Thank you |
||
| if matches(context, ServiceQueuesContext::OnInitialize) { | ||
| defensive!("Not enough weight to service a single message."); | ||
| } | ||
| Weight::zero() | ||
| }); | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 just noticed that this is implementing a trait function. Can you maybe put the inner logic into a new function and call that from here?
Having the
ServiceQueuesContextin the interface would be ugly otherwise.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 pushed a new commit last night (PST). Now that I'm re-reading this I might not have implemented the way you requested.
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 mean, the code does not compile? You are implementing a trait function. Please try to run the pallet tests locally.