Skip to content

Commit

Permalink
chore: add weight calculations for on_idle
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezs committed Sep 21, 2023
1 parent 600af8e commit 2c23295
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions state-chain/pallets/cf-ingress-egress/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod mock;
#[cfg(test)]
mod tests;
pub mod weights;
use frame_support::sp_runtime::SaturatedConversion;
pub use weights::WeightInfo;

use cf_chains::{
Expand Down Expand Up @@ -400,7 +401,20 @@ pub mod pallet {
let current_target_chain_height = T::ChainTracking::get_block_height();
let channel_lifetime = DepositChannelLifetime::<T, I>::get();

for (_, details) in DepositChannelLookup::<T, I>::iter() {
let read_write_weight =
frame_support::weights::constants::RocksDbWeight::get().reads_writes(1, 1);

let number_to_recycle = remaining_weight
.ref_time()
.checked_div(read_write_weight.ref_time())
.unwrap_or_default()
.saturated_into::<usize>();

let mut number_recycled = 0;
for (_, details) in
DepositChannelLookup::<T, I>::iter().take(number_to_recycle as usize)
{
number_recycled += 1;
// We add an extra lifetime of safety.
// The CFEs will stop witnessing the address of this deposit channel at the
// expires_at block number. However, because the CFE uses a safety margin, and here
Expand All @@ -418,8 +432,7 @@ pub mod pallet {
}
}

// TODO: return the actual weight
remaining_weight
read_write_weight.saturating_mul(number_recycled)
}

/// Take all scheduled Egress and send them out
Expand Down
2 changes: 1 addition & 1 deletion state-chain/pallets/cf-ingress-egress/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use crate::{self as pallet_cf_ingress_egress};
use crate::{DepositBalances, DepositChannelLifetime, DepositWitness};
use crate::{DepositBalances, DepositWitness};

pub use cf_chains::{
address::{AddressDerivationApi, ForeignChainAddress},
Expand Down

0 comments on commit 2c23295

Please sign in to comment.