Skip to content

Commit 3586218

Browse files
committed
Add OnTimestampSet implementation
1 parent 06dcdf3 commit 3586218

4 files changed

Lines changed: 212 additions & 195 deletions

File tree

pallets/scheduler/src/impls.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! Implementations for Scheduler pallet
2+
use super::*;
3+
4+
impl<T: Config> OnTimestampSet<T::Moment> for Pallet<T> {
5+
fn on_timestamp_set(now: T::Moment) {
6+
let mut weight_counter = WeightMeter::with_limit(T::MaximumWeight::get());
7+
Self::service_agendas(
8+
&mut weight_counter,
9+
BlockNumberOrTimestamp::Timestamp(now),
10+
u32::max_value(),
11+
);
12+
weight_counter.consumed();
13+
}
14+
}

pallets/scheduler/src/lib.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
#[cfg(feature = "runtime-benchmarks")]
6363
mod benchmarking;
64+
pub mod impls;
6465
#[cfg(test)]
6566
mod mock;
6667
#[cfg(test)]
@@ -78,8 +79,8 @@ use frame_support::{
7879
ensure,
7980
traits::{
8081
schedule::{self, DispatchTime as DispatchBlock, MaybeHashed},
81-
Bounded, CallerTrait, EnsureOrigin, Get, IsType, OriginTrait, PrivilegeCmp, QueryPreimage,
82-
StorageVersion, StorePreimage, Time,
82+
Bounded, CallerTrait, EnsureOrigin, Get, IsType, OnTimestampSet, OriginTrait, PrivilegeCmp,
83+
QueryPreimage, StorageVersion, StorePreimage, Time,
8384
},
8485
weights::{Weight, WeightMeter},
8586
};
@@ -89,7 +90,7 @@ use frame_system::{
8990
};
9091
use scale_info::TypeInfo;
9192
use sp_runtime::{
92-
traits::{BadOrigin, Block, CheckedDiv, Dispatchable, One, Saturating, Zero},
93+
traits::{BadOrigin, CheckedDiv, Dispatchable, One, Saturating, Zero},
9394
BoundedVec, DispatchError, RuntimeDebug,
9495
};
9596
use traits::ScheduleNamed;
@@ -145,14 +146,6 @@ where
145146
}
146147
}
147148

148-
/// Returns the timestamp if it is a timestamp.
149-
fn as_timestamp(&self) -> Option<Moment> {
150-
match self {
151-
BlockNumberOrTimestamp::BlockNumber(_) => None,
152-
BlockNumberOrTimestamp::Timestamp(x) => Some(*x),
153-
}
154-
}
155-
156149
/// Is zero
157150
fn is_zero(&self) -> bool {
158151
match self {
@@ -1489,13 +1482,13 @@ impl<T: Config>
14891482

14901483
fn next_dispatch_time(id: TaskName) -> Result<BlockNumberFor<T>, DispatchError> {
14911484
Lookup::<T>::get(id)
1485+
.ok_or(DispatchError::Unavailable)
14921486
.and_then(|(when, index)| {
14931487
Agenda::<T>::get(when)
14941488
.get(index as usize)
1495-
.map(|_| when.as_block_number())
1496-
.and_then(|x| x.ok_or(DispatchError::Unavailable))
1489+
.ok_or(DispatchError::Unavailable)
1490+
.and_then(|_| when.as_block_number().ok_or(DispatchError::Unavailable))
14971491
})
1498-
.ok_or(DispatchError::Unavailable)
14991492
}
15001493
}
15011494

0 commit comments

Comments
 (0)