@@ -100,14 +100,11 @@ use frame_support::{
100100 } ,
101101 weights:: { Weight , WeightMeter } ,
102102} ;
103- use frame_system:: {
104- pallet_prelude:: BlockNumberFor ,
105- { self as system} ,
106- } ;
103+ use frame_system:: { self as system} ;
107104use scale_info:: TypeInfo ;
108105use sp_io:: hashing:: blake2_256;
109106use sp_runtime:: {
110- traits:: { BadOrigin , Dispatchable , One , Saturating , Zero } ,
107+ traits:: { BadOrigin , BlockNumberProvider , Dispatchable , One , Saturating , Zero } ,
111108 BoundedVec , DispatchError , RuntimeDebug ,
112109} ;
113110
@@ -125,6 +122,9 @@ pub type CallOrHashOf<T> =
125122pub type BoundedCallOf < T > =
126123 Bounded < <T as Config >:: RuntimeCall , <T as frame_system:: Config >:: Hashing > ;
127124
125+ pub type BlockNumberFor < T > =
126+ <<T as Config >:: BlockNumberProvider as BlockNumberProvider >:: BlockNumber ;
127+
128128/// The configuration of the retry mechanism for a given task along with its current state.
129129#[ derive( Clone , Copy , RuntimeDebug , PartialEq , Eq , Encode , Decode , MaxEncodedLen , TypeInfo ) ]
130130pub struct RetryConfig < Period > {
@@ -230,7 +230,7 @@ impl<T: WeightInfo> MarginalWeightInfo for T {}
230230pub mod pallet {
231231 use super :: * ;
232232 use frame_support:: { dispatch:: PostDispatchInfo , pallet_prelude:: * } ;
233- use frame_system:: pallet_prelude:: * ;
233+ use frame_system:: pallet_prelude:: { BlockNumberFor as SystemBlockNumberFor , OriginFor } ;
234234
235235 /// The in-code storage version.
236236 const STORAGE_VERSION : StorageVersion = StorageVersion :: new ( 4 ) ;
@@ -292,6 +292,35 @@ pub mod pallet {
292292
293293 /// The preimage provider with which we look up call hashes to get the call.
294294 type Preimages : QueryPreimage < H = Self :: Hashing > + StorePreimage ;
295+
296+ /// Query the current block number.
297+ ///
298+ /// Must return monotonically increasing values when called from consecutive blocks. It is
299+ /// generally expected that the values also do not differ "too much" between consecutive
300+ /// blocks. A future addition to this pallet will allow bigger difference between
301+ /// consecutive blocks to make it possible to be utilized by parachains with *Agile
302+ /// Coretime*. *Agile Coretime* parachains are currently not supported and must continue to
303+ /// use their local block number provider.
304+ ///
305+ /// Can be configured to return either:
306+ /// - the local block number of the runtime via `frame_system::Pallet`
307+ /// - a remote block number, eg from the relay chain through `RelaychainDataProvider`
308+ /// - an arbitrary value through a custom implementation of the trait
309+ ///
310+ /// Suggested values:
311+ /// - Solo- and Relay-chains should use `frame_system::Pallet`. There are no concerns with
312+ /// this configuration.
313+ /// - Parachains should also use `frame_system::Pallet` for the time being. The scheduler
314+ /// pallet is not yet ready for the case that big numbers of blocks are skipped. In an
315+ /// *Agile Coretime* chain with relay chain number provider configured, it could otherwise
316+ /// happen that the scheduler will not be able to catch up to its agendas, since too many
317+ /// relay blocks are missing if the parachain only produces blocks rarely.
318+ ///
319+ /// There is currently no migration provided to "hot-swap" block number providers and it is
320+ /// therefore highly advised to stay with the default (local) values. If you still want to
321+ /// swap block number providers on the fly, then please at least ensure that you do not run
322+ /// any pallet migration in the same runtime upgrade.
323+ type BlockNumberProvider : BlockNumberProvider ;
295324 }
296325
297326 #[ pallet:: storage]
@@ -374,11 +403,12 @@ pub mod pallet {
374403 }
375404
376405 #[ pallet:: hooks]
377- impl < T : Config > Hooks < BlockNumberFor < T > > for Pallet < T > {
406+ impl < T : Config > Hooks < SystemBlockNumberFor < T > > for Pallet < T > {
378407 /// Execute the scheduled calls
379- fn on_initialize ( now : BlockNumberFor < T > ) -> Weight {
408+ fn on_initialize ( _now : SystemBlockNumberFor < T > ) -> Weight {
409+ let now = T :: BlockNumberProvider :: current_block_number ( ) ;
380410 let mut weight_counter = WeightMeter :: with_limit ( T :: MaximumWeight :: get ( ) ) ;
381- Self :: service_agendas ( & mut weight_counter, now, u32:: max_value ( ) ) ;
411+ Self :: service_agendas ( & mut weight_counter, now, u32:: MAX ) ;
382412 weight_counter. consumed ( )
383413 }
384414 }
@@ -889,8 +919,7 @@ impl<T: Config> Pallet<T> {
889919 fn resolve_time (
890920 when : DispatchTime < BlockNumberFor < T > > ,
891921 ) -> Result < BlockNumberFor < T > , DispatchError > {
892- let now = frame_system:: Pallet :: < T > :: block_number ( ) ;
893-
922+ let now = T :: BlockNumberProvider :: current_block_number ( ) ;
894923 let when = match when {
895924 DispatchTime :: At ( x) => x,
896925 // The current block has already completed it's scheduled tasks, so
@@ -1165,7 +1194,7 @@ impl<T: Config> Pallet<T> {
11651194 let mut count_down = max;
11661195 let service_agenda_base_weight = T :: WeightInfo :: service_agenda_base ( max_items) ;
11671196 while count_down > 0 && when <= now && weight. can_consume ( service_agenda_base_weight) {
1168- if !Self :: service_agenda ( weight, & mut executed, now, when, u32:: max_value ( ) ) {
1197+ if !Self :: service_agenda ( weight, & mut executed, now, when, u32:: MAX ) {
11691198 incomplete_since = incomplete_since. min ( when) ;
11701199 }
11711200 when. saturating_inc ( ) ;
0 commit comments