Skip to content

Commit

Permalink
Add on_initialize logs. (#1210)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch authored Oct 17, 2024
1 parent e792cb8 commit 2033240
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pallets/elections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
log::info!("on_initialize begin");
let mut weight = Weight::default();
for (network, _, _) in Unassigned::<T>::iter() {
weight = weight
// 1 Read of Unassigned per Loop
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(Self::try_elect_shard(network));
}
log::info!("on_initialize end");
weight
}
}
Expand Down
2 changes: 2 additions & 0 deletions pallets/members/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub mod pallet {
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
/// `on_initialize`: Handles periodic heartbeat checks and manages member online/offline statuses.
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
log::info!("on_initialize begin");
let mut weight = Weight::default();
if n % T::HeartbeatTimeout::get() == BlockNumberFor::<T>::default() {
for (member, _) in MemberOnline::<T>::iter() {
Expand All @@ -163,6 +164,7 @@ pub mod pallet {
T::DbWeight::get().writes(Heartbeat::<T>::drain().count() as u64),
);
}
log::info!("on_initialize end");
weight
}
}
Expand Down
2 changes: 2 additions & 0 deletions pallets/shards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
log::info!("on_initialize begin");
let mut writes = 0;
let mut reads = 0;
// use DkgTimeout instead
Expand All @@ -355,6 +356,7 @@ pub mod pallet {
reads += 1;
}
});
log::info!("on_initialize end");
T::DbWeight::get().reads_writes(reads, writes)
}
}
Expand Down
5 changes: 4 additions & 1 deletion pallets/tasks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,10 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
Self::schedule_tasks()
log::info!("on_initialize begin");
let weight = Self::schedule_tasks();
log::info!("on_initialize end");
weight
}
}

Expand Down

0 comments on commit 2033240

Please sign in to comment.