Skip to content

Commit

Permalink
reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
haider-rs committed Feb 14, 2025
1 parent 59ebfc1 commit e19435e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
42 changes: 27 additions & 15 deletions pallets/tasks/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use polkadot_sdk::{frame_benchmarking, frame_support, frame_system, sp_core, sp_
use sp_runtime::{BoundedVec, Vec};
use sp_std::vec;
use time_primitives::{
AccountId, Commitment, ElectionsInterface, ErrorMsg, GmpEvents, NetworkId, PublicKey,
AccountId, BatchId, Commitment, ElectionsInterface, ErrorMsg, GmpEvents, NetworkId, PublicKey,
ShardStatus, ShardsInterface, Task, TaskId, TaskResult, TasksInterface, TssPublicKey,
TssSignature,
};
Expand Down Expand Up @@ -145,27 +145,39 @@ benchmarks! {


restart_batch {
let l in 1..100;
create_shard::<T>(ETHEREUM);
let network = ETHEREUM;
let batch_id = BatchIdCounter::<T>::get();
let initial_task_id = Pallet::<T>::create_task(
network,
Task::SubmitGatewayMessage { batch_id }
);
FailedBatchIds::<T>::mutate(|ids| ids.push(batch_id));
BatchTaskId::<T>::insert(batch_id, initial_task_id);
TaskNetwork::<T>::insert(initial_task_id, network);
}: _(RawOrigin::Root, batch_id) verify {
let new_task_id = initial_task_id + 1;
let failed_batches: Vec<BatchId> = (0..l).map(|l| l as BatchId).collect();
let target_batch_id: u64 = (l - 1).into();

for batch_id in &failed_batches {
let task_id = Pallet::<T>::create_task(
network,
Task::SubmitGatewayMessage { batch_id: *batch_id }
);
BatchTaskId::<T>::insert(batch_id, task_id);
TaskNetwork::<T>::insert(task_id, network);
}

FailedBatchIds::<T>::put(failed_batches.clone());
}: _(RawOrigin::Root, target_batch_id) verify {
let new_task_id = TaskIdCounter::<T>::get();
assert_eq!(
BatchTaskId::<T>::get(batch_id),
BatchTaskId::<T>::get(target_batch_id),
Some(new_task_id),
"New task ID not properly set"
"New task not created"
);
assert!(
!FailedBatchIds::<T>::get().contains(&batch_id),
!FailedBatchIds::<T>::get().contains(&target_batch_id),
"Batch not removed from failed list"
);
}
assert_eq!(
FailedBatchIds::<T>::get().len(),
(l - 1) as usize,
"List length mismatch"
);

}
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
}
6 changes: 3 additions & 3 deletions pallets/tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub mod pallet {
fn sync_network() -> Weight;
fn stop_network() -> Weight;
fn remove_task() -> Weight;
fn restart_batch() -> Weight;
fn restart_batch(n: u32) -> Weight;
}

impl WeightInfo for () {
Expand All @@ -108,7 +108,7 @@ pub mod pallet {
fn remove_task() -> Weight {
Weight::default()
}
fn restart_batch() -> Weight {
fn restart_batch(_n: u32) -> Weight {
Weight::default()
}
}
Expand Down Expand Up @@ -451,7 +451,7 @@ pub mod pallet {
}

#[pallet::call_index(14)]
#[pallet::weight(<T as Config>::WeightInfo::restart_batch())]
#[pallet::weight(<T as Config>::WeightInfo::restart_batch(FailedBatchIds::<T>::decode_len().unwrap_or(0) as u32))]
pub fn restart_batch(origin: OriginFor<T>, batch_id: BatchId) -> DispatchResult {
T::AdminOrigin::ensure_origin(origin)?;
let old_task_id = BatchTaskId::<T>::get(batch_id).ok_or(Error::<T>::InvalidBatchId)?;
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/weights/develop/pallet_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<T: frame_system::Config> pallet_tasks::WeightInfo for WeightInfo<T> {
/// Proof: `Tasks::TaskSubmitter` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Tasks::TaskNetwork` (r:0 w:1)
/// Proof: `Tasks::TaskNetwork` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn restart_batch() -> Weight {
fn restart_batch(_n: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `286`
// Estimated: `3751`
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/weights/mainnet/pallet_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<T: frame_system::Config> pallet_tasks::WeightInfo for WeightInfo<T> {
/// Proof: `Tasks::TaskSubmitter` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Tasks::TaskNetwork` (r:0 w:1)
/// Proof: `Tasks::TaskNetwork` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn restart_batch() -> Weight {
fn restart_batch(_n: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `286`
// Estimated: `3751`
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/weights/testnet/pallet_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<T: frame_system::Config> pallet_tasks::WeightInfo for WeightInfo<T> {
/// Proof: `Tasks::TaskSubmitter` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Tasks::TaskNetwork` (r:0 w:1)
/// Proof: `Tasks::TaskNetwork` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn restart_batch() -> Weight {
fn restart_batch(_n: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `286`
// Estimated: `3751`
Expand Down

0 comments on commit e19435e

Please sign in to comment.