Skip to content

Commit

Permalink
Add on_initialize logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch committed Oct 17, 2024
1 parent d010149 commit 61559ec
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pallets/elections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,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 @@ -149,6 +149,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 @@ -168,6 +169,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 @@ -354,6 +354,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 @@ -373,6 +374,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 @@ -290,7 +290,10 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
Self::prepare_batches().saturating_add(Self::schedule_tasks())
log::info!("on_initialize begin");
let weight = Self::prepare_batches().saturating_add(Self::schedule_tasks());
log::info!("on_initialize end");
weight
}
}

Expand Down
1 change: 0 additions & 1 deletion pallets/tasks/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ pub fn roll(n: u64) {

fn next_block() {
let mut now = System::block_number();
Tasks::on_finalize(now);
now += 1;
System::set_block_number(now);
Shards::on_initialize(now);
Expand Down

0 comments on commit 61559ec

Please sign in to comment.