Skip to content

Commit

Permalink
Hook on_idle added
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Dec 31, 2024
1 parent 4b3ea70 commit 27f9107
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion substrate/frame/opf/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ impl<T: Config> Pallet<T> {
}

// To be executed in a hook, on_initialize
pub fn on_idle_function(now: ProvidedBlockNumberFor<T>, limit: Weight) -> Weight {
pub fn on_idle_function(limit: Weight) -> Weight {
let now = T::BlockNumberProvider::current_block_number();
let mut meter = WeightMeter::with_limit(limit);
let max_block_weight = T::DbWeight::get().reads_writes(14, 8);

Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/opf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ pub mod pallet {
MaximumProjectsNumber,
}

/*#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(n:ProvidedBlockNumberFor<T>) -> Weight {
Self::begin_block(n)
#[pallet::hooks]
impl<T: Config> Hooks<SystemBlockNumberFor<T>> for Pallet<T> {
fn on_idle(_n: SystemBlockNumberFor<T>, remaining_weight: Weight) -> Weight {
Self::on_idle_function(remaining_weight)
}
}*/
}

#[pallet::call]
impl<T: Config> Pallet<T> {
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/opf/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub type RoundIndex = u32;
pub type VoterId<T> = AccountIdOf<T>;
pub type ProvidedBlockNumberFor<T> =
<<T as Config>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;
pub use frame_system::pallet_prelude::BlockNumberFor as SystemBlockNumberFor;

/// The state of the payment claim.
#[derive(Encode, Decode, Clone, PartialEq, Eq, MaxEncodedLen, RuntimeDebug, TypeInfo, Default)]
Expand Down

0 comments on commit 27f9107

Please sign in to comment.