Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
open-runtime-module-library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Noxim
open-runtime-module-library
Commits
f778d611
Unverified
Commit
f778d611
authored
4 years ago
by
wangjj9219
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
allow at least one task even if the large tasks will consume whole block (#206)
parent
67d38469
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
schedule-update/src/lib.rs
+13
-9
13 additions, 9 deletions
schedule-update/src/lib.rs
with
13 additions
and
9 deletions
schedule-update/src/lib.rs
+
13
−
9
View file @
f778d611
...
...
@@ -12,7 +12,7 @@ use frame_support::{
use
frame_system
::{
self
as
system
,
ensure_root
,
ensure_signed
};
use
orml_traits
::{
DelayedDispatchTime
,
DispatchId
};
use
sp_runtime
::{
traits
::{
CheckedAdd
,
Dispatchable
,
One
},
traits
::{
CheckedAdd
,
Dispatchable
,
One
,
Zero
},
DispatchError
,
};
use
sp_std
::{
prelude
::
*
,
result
};
...
...
@@ -135,21 +135,23 @@ decl_module! {
}
fn
on_initialize
(
now
:
T
::
BlockNumber
)
->
Weight
{
let
mut
weight
:
Weight
=
0
;
let
total_weigh
t
=
T
::
MaxScheduleDispatchWeight
::
get
();
let
mut
cumulative_
weight
:
Weight
=
Zero
::
zero
()
;
let
weight_limi
t
=
T
::
MaxScheduleDispatchWeight
::
get
();
let
next_block_number
=
match
now
.checked_add
(
&
One
::
one
())
{
Some
(
block_number
)
=>
block_number
,
_
=>
return
weight
_
=>
return
cumulative_
weight
};
// Operational calls are dispatched first and then normal calls
// TODO: dispatches should be sorted
let
mut
operational_dispatches
=
<
DelayedOperationalDispatches
<
T
>>
::
iter_prefix
(
now
);
let
_
=
operational_dispatches
.try_for_each
(|(
_
,
(
who
,
call
,
id
))|
{
weight
+=
call
.get_dispatch_info
()
.weight
;
if
weight
>
total_weight
{
let
call_weight
=
call
.get_dispatch_info
()
.weight
;
// allowed to handle at least one task when no one task has been handled in this block even if the weight exceeds `MaxScheduleDispatchWeight`
if
cumulative_weight
+
call_weight
>
weight_limit
&&
!
cumulative_weight
.is_zero
()
{
return
Err
(
Error
::
<
T
>
::
ExceedMaxScheduleDispatchWeight
);
}
cumulative_weight
+=
call_weight
;
let
origin
:
T
::
Origin
;
if
let
Some
(
w
)
=
who
{
...
...
@@ -170,10 +172,12 @@ decl_module! {
let
mut
normal_dispatches
=
<
DelayedNormalDispatches
<
T
>>
::
iter_prefix
(
now
);
let
_
=
normal_dispatches
.try_for_each
(|(
_
,
(
who
,
call
,
id
))|
{
weight
+=
call
.get_dispatch_info
()
.weight
;
if
weight
>
total_weight
{
let
call_weight
=
call
.get_dispatch_info
()
.weight
;
// allowed to handle at least one task when no one task has been handled in this block even if the weight exceeds `MaxScheduleDispatchWeight`
if
cumulative_weight
+
call_weight
>
weight_limit
&&
!
cumulative_weight
.is_zero
()
{
return
Err
(
Error
::
<
T
>
::
ExceedMaxScheduleDispatchWeight
);
}
cumulative_weight
+=
call_weight
;
let
origin
:
T
::
Origin
;
if
let
Some
(
w
)
=
who
{
...
...
@@ -206,7 +210,7 @@ decl_module! {
<
DelayedNormalDispatches
<
T
>>
::
remove
(
now
,
id
);
});
0
cumulative_weight
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment