Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add on_initialize logs. #1210

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading