-
Notifications
You must be signed in to change notification settings - Fork 4
Configurable assigned task limit per Network #873
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
Changes from 8 commits
064fb25
e022023
578909f
4e3ec38
2209212
6b1aa91
bde8242
454c74f
ec16c07
285329b
c31ba11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ pub mod pallet { | |
| fn set_send_message_task_reward() -> Weight; | ||
| fn cancel_task() -> Weight; | ||
| fn reset_tasks() -> Weight; | ||
| fn set_shard_task_limit() -> Weight; | ||
| fn unregister_gateways() -> Weight; | ||
| } | ||
|
|
||
|
|
@@ -85,6 +86,10 @@ pub mod pallet { | |
| Weight::default() | ||
| } | ||
|
|
||
| fn set_shard_task_limit() -> Weight { | ||
| Weight::default() | ||
| } | ||
|
|
||
| fn unregister_gateways() -> Weight { | ||
| Weight::default() | ||
| } | ||
|
|
@@ -134,6 +139,11 @@ pub mod pallet { | |
| pub type UnassignedTasks<T: Config> = | ||
| StorageDoubleMap<_, Blake2_128Concat, NetworkId, Blake2_128Concat, TaskId, (), OptionQuery>; | ||
|
|
||
| #[pallet::storage] | ||
| #[pallet::getter(fn shard_task_limit)] | ||
| pub type ShardTaskLimit<T: Config> = | ||
| StorageMap<_, Blake2_128Concat, NetworkId, u64, OptionQuery>; | ||
|
|
||
| #[pallet::storage] | ||
| pub type ShardTasks<T: Config> = | ||
| StorageDoubleMap<_, Blake2_128Concat, ShardId, Blake2_128Concat, TaskId, (), OptionQuery>; | ||
|
|
@@ -252,6 +262,8 @@ pub mod pallet { | |
| WriteTaskRewardSet(NetworkId, BalanceOf<T>), | ||
| /// Send message task reward set for network | ||
| SendMessageTaskRewardSet(NetworkId, BalanceOf<T>), | ||
| /// Set the maximum number of assigned tasks for all shards on the network | ||
| ShardTaskLimitSet(NetworkId, u64), | ||
| } | ||
|
|
||
| #[pallet::error] | ||
|
|
@@ -472,7 +484,7 @@ pub mod pallet { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[pallet::call_index(10)] | ||
| #[pallet::call_index(9)] | ||
| #[pallet::weight(<T as Config>::WeightInfo::cancel_task())] | ||
| pub fn sudo_cancel_tasks(origin: OriginFor<T>) -> DispatchResult { | ||
| ensure_root(origin)?; | ||
|
|
@@ -487,7 +499,7 @@ pub mod pallet { | |
| Ok(()) | ||
| } | ||
|
|
||
| #[pallet::call_index(9)] | ||
| #[pallet::call_index(10)] | ||
| #[pallet::weight(<T as Config>::WeightInfo::reset_tasks())] | ||
| pub fn reset_tasks(origin: OriginFor<T>) -> DispatchResult { | ||
| ensure_root(origin)?; | ||
|
|
@@ -509,6 +521,19 @@ pub mod pallet { | |
| } | ||
|
|
||
| #[pallet::call_index(11)] | ||
| #[pallet::weight(<T as Config>::WeightInfo::set_shard_task_limit())] | ||
| pub fn set_shard_task_limit( | ||
| origin: OriginFor<T>, | ||
| network: NetworkId, | ||
| limit: u64, | ||
| ) -> DispatchResult { | ||
| ensure_root(origin)?; | ||
| ShardTaskLimit::<T>::insert(network, limit); | ||
| Self::deposit_event(Event::ShardTaskLimitSet(network, limit)); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[pallet::call_index(12)] | ||
| #[pallet::weight(<T as Config>::WeightInfo::unregister_gateways())] | ||
| pub fn unregister_gateways(origin: OriginFor<T>) -> DispatchResult { | ||
| ensure_root(origin)?; | ||
|
|
@@ -814,10 +839,22 @@ pub mod pallet { | |
| } | ||
|
|
||
| fn schedule_tasks_shard(network: NetworkId, shard_id: ShardId) { | ||
| let tasks = ShardTasks::<T>::iter_prefix(shard_id).count(); | ||
| let tasks = ShardTasks::<T>::iter_prefix(shard_id) | ||
| .filter(|(t, _)| TaskOutput::<T>::get(t).is_none()) | ||
| .count(); | ||
| let shard_size = T::Shards::shard_members(shard_id).len() as u16; | ||
| let is_registered = ShardRegistered::<T>::get(shard_id).is_some(); | ||
| let capacity = 10.saturating_sub(tasks); | ||
| const PREV_HARDCODED_LIMIT: usize = 10; | ||
| let shard_task_limit: usize = if let Some(limit) = ShardTaskLimit::<T>::get(network) { | ||
| limit.try_into().unwrap_or(PREV_HARDCODED_LIMIT) | ||
| } else { | ||
| PREV_HARDCODED_LIMIT | ||
| }; | ||
amarsinghcodes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let capacity = shard_task_limit.saturating_sub(tasks); | ||
| if capacity.is_zero() { | ||
| // no new tasks assigned if capacity reached or exceeded | ||
| return; | ||
| } | ||
|
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. we already handle the zero case later no?
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. We |
||
| let tasks = UnassignedTasks::<T>::iter_prefix(network) | ||
| .filter(|(task_id, _)| { | ||
| let Some(task) = Tasks::<T>::get(task_id) else { return false }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.