Skip to content

Commit

Permalink
fix: remove unused events and hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
shekohex committed Jan 5, 2024
1 parent a82b0f9 commit c46a791
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 60 deletions.
42 changes: 1 addition & 41 deletions pallets/jobs/src/functions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use sp_runtime::traits::{One, Zero};
use sp_runtime::traits::Zero;
use tangle_primitives::{
jobs::{
DKGTSSPhaseOneJobType, DKGTSSSignatureResult, JobType, JobWithResult, ZkSaaSCircuitResult,
Expand Down Expand Up @@ -474,44 +474,4 @@ impl<T: Config> Pallet<T> {
};
Ok(result)
}

pub fn on_idle_remove_expired_jobs(
now: BlockNumberFor<T>,
mut remaining_weight: Weight,
) -> Weight {
// early return if we dont have enough weight to perform a read
if remaining_weight.is_zero() {
return remaining_weight
}

// fetch all known results
let known_results = KnownResults::<T>::iter();
// we use size hint to avoid reallocations
let known_results_len = known_results.size_hint().0 as u64;
remaining_weight =
remaining_weight.saturating_sub(T::DbWeight::get().reads(known_results_len));

let results_to_remove = known_results.filter_map(|(role_type, job_id, result)| {
if result.ttl < now {
Some((role_type, job_id))
} else {
None
}
});

for (role_type, job_id) in results_to_remove {
// remaining_weight =
// remaining_weight.saturating_sub(T::DbWeight::get().reads(One::one()));

if remaining_weight.is_zero() {
break
}

Self::deposit_event(Event::<T>::JobResultExpired { role_type, job_id });
// DO NOT REMOVE RESULTS KEEP THEM FOR NOW.
// KnownResults::<T>::remove(role_type, job_id);
}

remaining_weight
}
}
19 changes: 0 additions & 19 deletions pallets/jobs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ pub mod module {
JobSubmitted { job_id: JobId, role_type: RoleType, details: JobSubmissionOf<T> },
/// A new job result has been submitted
JobResultSubmitted { job_id: JobId, role_type: RoleType },
/// A Job Result has expired.
/// No more submissions will be accepted for this job.
JobResultExpired { job_id: JobId, role_type: RoleType },
/// validator has earned reward
ValidatorRewarded { id: T::AccountId, reward: BalanceOf<T> },
}
Expand Down Expand Up @@ -542,20 +539,4 @@ pub mod module {
})
}
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
/// Hook that execute when there is leftover space in a block
/// This function will execute on even blocks and move any proposals
/// in unsigned proposals to unsigned proposal queue
fn on_idle(now: BlockNumberFor<T>, remaining_weight: Weight) -> Weight {
// execute on even blocks
if now % 2_u32.into() != 0_u32.into() {
return remaining_weight
}

// remove expired jobs with remaining weight
Self::on_idle_remove_expired_jobs(now, remaining_weight)
}
}
}

0 comments on commit c46a791

Please sign in to comment.