Skip to content

Commit

Permalink
simplify weight computation
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Aug 23, 2024
1 parent 0a17eee commit 69200a5
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 122 deletions.
1 change: 0 additions & 1 deletion libs/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ pub trait TrancheTokenPrice<AccountId, CurrencyId> {
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub enum UpdateState {
NoExecution,
Executed(u32),
Stored(u32),
}

Expand Down
13 changes: 4 additions & 9 deletions pallets/pool-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ pub mod pallet {
Registered { pool_id: T::PoolId },
/// A pool update was registered.
UpdateRegistered { pool_id: T::PoolId },
/// A pool update was executed.
UpdateExecuted { pool_id: T::PoolId },
/// A pool update was stored for later execution.
UpdateStored { pool_id: T::PoolId },
/// Pool metadata was set.
Expand Down Expand Up @@ -248,7 +246,7 @@ pub mod pallet {
///
/// The caller must have the `PoolAdmin` role in order to
/// invoke this extrinsic.
#[pallet::weight(T::WeightInfo::update_and_execute(MaxTranches::<T>::get()))]
#[pallet::weight(T::WeightInfo::update(MaxTranches::<T>::get()))]
#[pallet::call_index(1)]
pub fn update(
origin: OriginFor<T>,
Expand Down Expand Up @@ -279,16 +277,13 @@ pub mod pallet {
Self::deposit_event(Event::UpdateRegistered { pool_id });

let weight = match state {
UpdateState::NoExecution => T::WeightInfo::update_no_execution(0),
UpdateState::Executed(num_tranches) => {
Self::deposit_event(Event::UpdateExecuted { pool_id });
T::WeightInfo::update_and_execute(num_tranches)
}
UpdateState::NoExecution => T::WeightInfo::update(0),
UpdateState::Stored(num_tranches) => {
Self::deposit_event(Event::UpdateStored { pool_id });
T::WeightInfo::update_no_execution(num_tranches)
T::WeightInfo::update(num_tranches)
}
};

Ok(Some(weight).into())
}

Expand Down
9 changes: 2 additions & 7 deletions pallets/pool-registry/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use frame_support::weights::Weight;

pub trait WeightInfo {
fn register(n: u32, m: u32) -> Weight;
fn update_no_execution(n: u32) -> Weight;
fn update_and_execute(n: u32) -> Weight;
fn update(n: u32) -> Weight;
fn execute_update(n: u32) -> Weight;
fn set_metadata() -> Weight;
}
Expand All @@ -26,11 +25,7 @@ impl WeightInfo for () {
Weight::zero()
}

fn update_no_execution(_n: u32) -> Weight {
Weight::zero()
}

fn update_and_execute(_n: u32) -> Weight {
fn update(_n: u32) -> Weight {
Weight::zero()
}

Expand Down
13 changes: 3 additions & 10 deletions pallets/pool-system/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,10 @@ impl<T: Config> PoolMutate<T::AccountId, T::PoolId> for Pallet<T> {
submitted_at: now,
};

let num_tranches = pool.tranches.num_tranches().try_into().unwrap();
if T::MinUpdateDelay::get() == 0 && T::UpdateGuard::released(&pool, &update, now) {
Self::do_update_pool(&pool_id, &changes)?;
ScheduledUpdate::<T>::insert(pool_id, update);

Ok(UpdateState::Executed(num_tranches))
} else {
// If an update was already stored, this will override it
ScheduledUpdate::<T>::insert(pool_id, update);

Ok(UpdateState::Stored(num_tranches))
}
let num_tranches = pool.tranches.num_tranches().ensure_into()?;
Ok(UpdateState::Stored(num_tranches))
}

fn execute_update(pool_id: T::PoolId) -> Result<u32, DispatchError> {
Expand Down
33 changes: 1 addition & 32 deletions runtime/altair/src/weights/pallet_pool_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,37 +83,6 @@ impl<T: frame_system::Config> pallet_pool_registry::WeightInfo for WeightInfo<T>
/// Proof: `Permissions::Permission` (`max_values`: None, `max_size`: Some(228), added: 2703, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::EpochExecution` (r:1 w:0)
/// Proof: `PoolSystem::EpochExecution` (`max_values`: None, `max_size`: Some(754), added: 3229, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::Pool` (r:1 w:0)
/// Proof: `PoolSystem::Pool` (`max_values`: None, `max_size`: Some(813), added: 3288, mode: `MaxEncodedLen`)
/// Storage: `Timestamp::Now` (r:1 w:0)
/// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `Investments::ActiveRedeemOrders` (r:5 w:0)
/// Proof: `Investments::ActiveRedeemOrders` (`max_values`: None, `max_size`: Some(56), added: 2531, mode: `MaxEncodedLen`)
/// Storage: `PoolFees::ActiveFees` (r:1 w:0)
/// Proof: `PoolFees::ActiveFees` (`max_values`: None, `max_size`: Some(14043), added: 16518, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::ScheduledUpdate` (r:0 w:1)
/// Proof: `PoolSystem::ScheduledUpdate` (`max_values`: None, `max_size`: Some(1504), added: 3979, mode: `MaxEncodedLen`)
/// The range of component `n` is `[1, 5]`.
/// The range of component `m` is `[0, 100]`.
fn update_no_execution(n: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `924 + m * (124 ±0) + n * (133 ±0)`
// Estimated: `17508 + n * (2531 ±0)`
// Minimum execution time: 58_639_000 picoseconds.
Weight::from_parts(49_321_092, 0)
.saturating_add(Weight::from_parts(0, 17508))
// Standard Error: 32_924
.saturating_add(Weight::from_parts(2_803_470, 0).saturating_mul(n.into()))
// Standard Error: 1_502
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into())))
.saturating_add(T::DbWeight::get().writes(1))
.saturating_add(Weight::from_parts(0, 2531).saturating_mul(n.into()))
}
/// Storage: `Permissions::Permission` (r:1 w:0)
/// Proof: `Permissions::Permission` (`max_values`: None, `max_size`: Some(228), added: 2703, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::EpochExecution` (r:1 w:0)
/// Proof: `PoolSystem::EpochExecution` (`max_values`: None, `max_size`: Some(754), added: 3229, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::Pool` (r:1 w:1)
/// Proof: `PoolSystem::Pool` (`max_values`: None, `max_size`: Some(813), added: 3288, mode: `MaxEncodedLen`)
/// Storage: `Timestamp::Now` (r:1 w:0)
Expand All @@ -128,7 +97,7 @@ impl<T: frame_system::Config> pallet_pool_registry::WeightInfo for WeightInfo<T>
/// Proof: `PoolSystem::ScheduledUpdate` (`max_values`: None, `max_size`: Some(1504), added: 3979, mode: `MaxEncodedLen`)
/// The range of component `n` is `[1, 5]`.
/// The range of component `m` is `[0, 100]`.
fn update_and_execute(n: u32) -> Weight {
fn update(n: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `927 + m * (124 ±0) + n * (200 ±0)`
// Estimated: `17508 + n * (3417 ±0)`
Expand Down
33 changes: 1 addition & 32 deletions runtime/centrifuge/src/weights/pallet_pool_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,37 +85,6 @@ impl<T: frame_system::Config> pallet_pool_registry::WeightInfo for WeightInfo<T>
/// Proof: `Permissions::Permission` (`max_values`: None, `max_size`: Some(228), added: 2703, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::EpochExecution` (r:1 w:0)
/// Proof: `PoolSystem::EpochExecution` (`max_values`: None, `max_size`: Some(754), added: 3229, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::Pool` (r:1 w:0)
/// Proof: `PoolSystem::Pool` (`max_values`: None, `max_size`: Some(813), added: 3288, mode: `MaxEncodedLen`)
/// Storage: `Timestamp::Now` (r:1 w:0)
/// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `Investments::ActiveRedeemOrders` (r:5 w:0)
/// Proof: `Investments::ActiveRedeemOrders` (`max_values`: None, `max_size`: Some(56), added: 2531, mode: `MaxEncodedLen`)
/// Storage: `PoolFees::ActiveFees` (r:1 w:0)
/// Proof: `PoolFees::ActiveFees` (`max_values`: None, `max_size`: Some(14043), added: 16518, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::ScheduledUpdate` (r:0 w:1)
/// Proof: `PoolSystem::ScheduledUpdate` (`max_values`: None, `max_size`: Some(1504), added: 3979, mode: `MaxEncodedLen`)
/// The range of component `n` is `[1, 5]`.
/// The range of component `m` is `[0, 100]`.
fn update_no_execution(n: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `957 + m * (124 ±0) + n * (133 ±0)`
// Estimated: `17508 + n * (2531 ±0)`
// Minimum execution time: 58_350_000 picoseconds.
Weight::from_parts(49_218_674, 0)
.saturating_add(Weight::from_parts(0, 17508))
// Standard Error: 39_378
.saturating_add(Weight::from_parts(2_932_409, 0).saturating_mul(n.into()))
// Standard Error: 1_796
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into())))
.saturating_add(T::DbWeight::get().writes(1))
.saturating_add(Weight::from_parts(0, 2531).saturating_mul(n.into()))
}
/// Storage: `Permissions::Permission` (r:1 w:0)
/// Proof: `Permissions::Permission` (`max_values`: None, `max_size`: Some(228), added: 2703, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::EpochExecution` (r:1 w:0)
/// Proof: `PoolSystem::EpochExecution` (`max_values`: None, `max_size`: Some(754), added: 3229, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::Pool` (r:1 w:1)
/// Proof: `PoolSystem::Pool` (`max_values`: None, `max_size`: Some(813), added: 3288, mode: `MaxEncodedLen`)
/// Storage: `Timestamp::Now` (r:1 w:0)
Expand All @@ -130,7 +99,7 @@ impl<T: frame_system::Config> pallet_pool_registry::WeightInfo for WeightInfo<T>
/// Proof: `PoolSystem::ScheduledUpdate` (`max_values`: None, `max_size`: Some(1504), added: 3979, mode: `MaxEncodedLen`)
/// The range of component `n` is `[1, 5]`.
/// The range of component `m` is `[0, 100]`.
fn update_and_execute(n: u32) -> Weight {
fn update(n: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `960 + m * (124 ±0) + n * (200 ±0)`
// Estimated: `17508 + n * (3417 ±0)`
Expand Down
32 changes: 1 addition & 31 deletions runtime/development/src/weights/pallet_pool_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,36 +85,6 @@ impl<T: frame_system::Config> pallet_pool_registry::WeightInfo for WeightInfo<T>
/// Proof: `Permissions::Permission` (`max_values`: None, `max_size`: Some(228), added: 2703, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::EpochExecution` (r:1 w:0)
/// Proof: `PoolSystem::EpochExecution` (`max_values`: None, `max_size`: Some(754), added: 3229, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::Pool` (r:1 w:0)
/// Proof: `PoolSystem::Pool` (`max_values`: None, `max_size`: Some(813), added: 3288, mode: `MaxEncodedLen`)
/// Storage: `Timestamp::Now` (r:1 w:0)
/// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `Investments::ActiveRedeemOrders` (r:5 w:0)
/// Proof: `Investments::ActiveRedeemOrders` (`max_values`: None, `max_size`: Some(56), added: 2531, mode: `MaxEncodedLen`)
/// Storage: `PoolFees::ActiveFees` (r:1 w:0)
/// Proof: `PoolFees::ActiveFees` (`max_values`: None, `max_size`: Some(14043), added: 16518, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::ScheduledUpdate` (r:0 w:1)
/// Proof: `PoolSystem::ScheduledUpdate` (`max_values`: None, `max_size`: Some(1504), added: 3979, mode: `MaxEncodedLen`)
/// The range of component `n` is `[1, 5]`.
/// The range of component `m` is `[0, 100]`.
fn update_no_execution(n: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `957 + m * (124 ±0) + n * (133 ±0)`
// Estimated: `17508 + n * (2531 ±0)`
// Minimum execution time: 58_350_000 picoseconds.
Weight::from_parts(49_218_674, 0)
.saturating_add(Weight::from_parts(0, 17508))
// Standard Error: 39_378
.saturating_add(Weight::from_parts(2_932_409, 0).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into())))
.saturating_add(T::DbWeight::get().writes(1))
.saturating_add(Weight::from_parts(0, 2531).saturating_mul(n.into()))
}
/// Storage: `Permissions::Permission` (r:1 w:0)
/// Proof: `Permissions::Permission` (`max_values`: None, `max_size`: Some(228), added: 2703, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::EpochExecution` (r:1 w:0)
/// Proof: `PoolSystem::EpochExecution` (`max_values`: None, `max_size`: Some(754), added: 3229, mode: `MaxEncodedLen`)
/// Storage: `PoolSystem::Pool` (r:1 w:1)
/// Proof: `PoolSystem::Pool` (`max_values`: None, `max_size`: Some(813), added: 3288, mode: `MaxEncodedLen`)
/// Storage: `Timestamp::Now` (r:1 w:0)
Expand All @@ -129,7 +99,7 @@ impl<T: frame_system::Config> pallet_pool_registry::WeightInfo for WeightInfo<T>
/// Proof: `PoolSystem::ScheduledUpdate` (`max_values`: None, `max_size`: Some(1504), added: 3979, mode: `MaxEncodedLen`)
/// The range of component `n` is `[1, 5]`.
/// The range of component `m` is `[0, 100]`.
fn update_and_execute(n: u32) -> Weight {
fn update(n: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `960 + m * (124 ±0) + n * (200 ±0)`
// Estimated: `17508 + n * (3417 ±0)`
Expand Down

0 comments on commit 69200a5

Please sign in to comment.