From 5ad5702ab17a3dc2ab1cb8f4c033e1b6966501f5 Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Fri, 19 Jul 2024 14:50:20 +0500 Subject: [PATCH 1/5] fix task distribution --- pallets/tasks/src/lib.rs | 6 +++--- pallets/tasks/src/tests.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/pallets/tasks/src/lib.rs b/pallets/tasks/src/lib.rs index 238c531b2..81ec798f9 100644 --- a/pallets/tasks/src/lib.rs +++ b/pallets/tasks/src/lib.rs @@ -658,7 +658,7 @@ pub mod pallet { /// Sets the reward for write tasks. /// - // # Flow + /// # Flow /// 1. Ensure the origin of the transaction is a root user. /// 2. Insert the new reward amount for the specified network into the [`NetworkWriteReward`] storage. /// 3. Emit an event [`Event::WriteTaskRewardSet`] indicating the write task reward has been set. @@ -1275,7 +1275,7 @@ pub mod pallet { /// - Retrieve all shards associated with the `network`. /// - Collect these shards into a list. /// - Sort the list based on the number of tasks each shard currently has. - /// - Iterate through the sorted list in reverse order. + /// - Iterate through the sorted list. /// - For each shard in the list, call [`Self::schedule_tasks_shard`] to schedule tasks. fn schedule_tasks(network: NetworkId, shard_id: Option) { if let Some(shard_id) = shard_id { @@ -1287,7 +1287,7 @@ pub mod pallet { .count() .cmp(&ShardTasks::::iter_prefix(*b).count()) }); - shards.into_iter().rev().for_each(|(shard, _)| { + shards.into_iter().for_each(|(shard, _)| { Self::schedule_tasks_shard(network, shard); }); } diff --git a/pallets/tasks/src/tests.rs b/pallets/tasks/src/tests.rs index 3e3ac096b..a14525de8 100644 --- a/pallets/tasks/src/tests.rs +++ b/pallets/tasks/src/tests.rs @@ -1813,6 +1813,34 @@ fn test_task_execution_order() { }); } +#[test] +fn test_multi_shard_distribution() { + new_test_ext().execute_with(|| { + // Shard creation + for i in 0..3 { + Shards::create_shard( + ETHEREUM, + [[0u8; 32].into(), [1u8; 32].into(), [2u8; 32].into()].to_vec(), + 1, + ); + ShardState::::insert(i, ShardStatus::Online); + Tasks::shard_online(i, ETHEREUM); + } + + // Tasks creation and assingment + for _ in 0..9 { + assert_ok!(Tasks::create_task( + RawOrigin::Signed([0; 32].into()).into(), + mock_task(ETHEREUM, 3) + )); + } + + assert_eq!(ShardTasks::::iter_prefix(0).count(), 3); + assert_eq!(ShardTasks::::iter_prefix(1).count(), 3); + assert_eq!(ShardTasks::::iter_prefix(2).count(), 3); + }); +} + #[test] fn test_assingment_with_diff_shard_size() { new_test_ext().execute_with(|| { From 6d339409f8f116e70d3f9579bd40d20e40b5e19f Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Fri, 19 Jul 2024 17:11:24 +0500 Subject: [PATCH 2/5] add task more than limit --- pallets/tasks/src/tests.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pallets/tasks/src/tests.rs b/pallets/tasks/src/tests.rs index a14525de8..905b3a662 100644 --- a/pallets/tasks/src/tests.rs +++ b/pallets/tasks/src/tests.rs @@ -1841,6 +1841,36 @@ fn test_multi_shard_distribution() { }); } +#[test] +fn test_multi_shard_distribution_task_more_than_limit() { + new_test_ext().execute_with(|| { + // Shard creation + for i in 0..3 { + Shards::create_shard( + ETHEREUM, + [[0u8; 32].into(), [1u8; 32].into(), [2u8; 32].into()].to_vec(), + 1, + ); + ShardState::::insert(i, ShardStatus::Online); + Tasks::shard_online(i, ETHEREUM); + } + + assert_ok!(Tasks::set_shard_task_limit(RawOrigin::Root.into(), ETHEREUM, 5)); + + // Tasks creation and assingment + for _ in 0..30 { + assert_ok!(Tasks::create_task( + RawOrigin::Signed([0; 32].into()).into(), + mock_task(ETHEREUM, 3) + )); + } + + assert_eq!(ShardTasks::::iter_prefix(0).count(), 5); + assert_eq!(ShardTasks::::iter_prefix(1).count(), 5); + assert_eq!(ShardTasks::::iter_prefix(2).count(), 5); + }); +} + #[test] fn test_assingment_with_diff_shard_size() { new_test_ext().execute_with(|| { From 314ad5524eda1e828b6cd990122605b7c7496582 Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Fri, 19 Jul 2024 18:44:34 +0500 Subject: [PATCH 3/5] add more test --- pallets/tasks/src/tests.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/pallets/tasks/src/tests.rs b/pallets/tasks/src/tests.rs index 905b3a662..05a9a511e 100644 --- a/pallets/tasks/src/tests.rs +++ b/pallets/tasks/src/tests.rs @@ -1871,6 +1871,40 @@ fn test_multi_shard_distribution_task_more_than_limit() { }); } +#[test] +fn test_multi_shard_distribution_task_more_than_limit_before_shard_online() { + new_test_ext().execute_with(|| { + // Shard creation + for i in 0..3 { + Shards::create_shard( + ETHEREUM, + [[0u8; 32].into(), [1u8; 32].into(), [2u8; 32].into()].to_vec(), + 1, + ); + ShardState::::insert(i, ShardStatus::Online); + } + + assert_ok!(Tasks::set_shard_task_limit(RawOrigin::Root.into(), ETHEREUM, 10)); + + // Tasks creation and assingment + for _ in 0..25 { + assert_ok!(Tasks::create_task( + RawOrigin::Signed([0; 32].into()).into(), + mock_task(ETHEREUM, 3) + )); + } + + // shards come online when there are already some pending tasks to work with + for i in 0..3 { + Tasks::shard_online(i, ETHEREUM); + } + + assert_eq!(ShardTasks::::iter_prefix(0).count(), 10); + assert_eq!(ShardTasks::::iter_prefix(1).count(), 10); + assert_eq!(ShardTasks::::iter_prefix(2).count(), 5); + }); +} + #[test] fn test_assingment_with_diff_shard_size() { new_test_ext().execute_with(|| { From 887c49b47d8c50c04d05cfb0e72775a574eead8e Mon Sep 17 00:00:00 2001 From: Haider-Ali-DS Date: Fri, 19 Jul 2024 18:57:05 +0500 Subject: [PATCH 4/5] rename test --- pallets/tasks/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/tasks/src/tests.rs b/pallets/tasks/src/tests.rs index 05a9a511e..937568f02 100644 --- a/pallets/tasks/src/tests.rs +++ b/pallets/tasks/src/tests.rs @@ -1872,7 +1872,7 @@ fn test_multi_shard_distribution_task_more_than_limit() { } #[test] -fn test_multi_shard_distribution_task_more_than_limit_before_shard_online() { +fn test_multi_shard_distribution_task_before_shard_online() { new_test_ext().execute_with(|| { // Shard creation for i in 0..3 { From c503b404bc4fc6414888459345b911ec8abaf0f7 Mon Sep 17 00:00:00 2001 From: Metadata Update Bot Date: Fri, 19 Jul 2024 14:09:19 +0000 Subject: [PATCH 5/5] tc-subxt: Automatic metadata update --- config/subxt/mainnet.default.scale | Bin 317962 -> 317969 bytes config/subxt/mainnet.development.scale | Bin 317958 -> 317965 bytes config/subxt/testnet.default.scale | Bin 177739 -> 177746 bytes config/subxt/testnet.development.scale | Bin 177747 -> 177754 bytes 4 files changed, 0 insertions(+), 0 deletions(-) diff --git a/config/subxt/mainnet.default.scale b/config/subxt/mainnet.default.scale index 9dc77fe1d674b99e6c12057fac2f5774a86d5290..e47ba864df8b6b22f76ba65591884c6fb7977428 100644 GIT binary patch delta 39 tcmeC$B0O=6a6=2@7AEfsMw#h86--LgrK*^m+E-RE0WtITl@%L?HekXfS7svh6fRrmxIlRGO}t&FIw5mdm)EEtkpF69Dd!3*rC( delta 33 pcmccghU@eju7)j)D{>emrmxIlRGMy(&1l`uo6ESJHfRrmxIlRGO}t&FIw5mdm)EEtkpH69Dj;3;F;6 delta 33 pcmcchhU@Yhu7)j)D{>emrmxIlRGMy(&1l`uo6ESJH