Skip to content

Commit

Permalink
more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lemunozm committed Aug 23, 2024
1 parent 5c4e41a commit 4028587
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 39 deletions.
10 changes: 10 additions & 0 deletions libs/mocks/src/pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ pub mod pallet {
pub fn mock_execute_update(f: impl Fn(T::PoolId) -> Result<u32, DispatchError> + 'static) {
register_call!(f);
}

#[cfg(feature = "runtime-benchmarks")]
pub fn mock_worst_pool_changes(f: impl Fn(Option<u32>) -> T::PoolChanges + 'static) {
register_call!(f);
}
}

impl<T: ConfigMut> PoolMutate<T::AccountId, T::PoolId> for Pallet<T> {
Expand Down Expand Up @@ -290,5 +295,10 @@ pub mod pallet {
fn execute_update(a: T::PoolId) -> Result<u32, DispatchError> {
execute_call!(a)
}

#[cfg(feature = "runtime-benchmarks")]
fn worst_pool_changes(a: Option<u32>) -> Self::PoolChanges {
execute_call!(a)
}
}
}
17 changes: 8 additions & 9 deletions libs/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,23 @@ pub trait PoolMutate<AccountId, PoolId> {

/// A worst case list of tranches
#[cfg(feature = "runtime-benchmarks")]
fn worst_tranche_input_list(_: u32) -> BoundedVec<Self::TrancheInput, Self::MaxTranches> {
fn worst_tranche_input_list(
_num_tranches: u32,
) -> BoundedVec<Self::TrancheInput, Self::MaxTranches> {
Default::default()
}

/// A worst case list of pool fees
#[cfg(feature = "runtime-benchmarks")]
fn worst_fee_input_list(_: u32) -> BoundedVec<Self::PoolFeeInput, Self::MaxFeesPerPool> {
fn worst_fee_input_list(
_num_pool_fees: u32,
) -> BoundedVec<Self::PoolFeeInput, Self::MaxFeesPerPool> {
Default::default()
}

/// A worst case change
#[cfg(feature = "runtime-benchmarks")]
fn worst_pool_changes(_: Option<u32>) -> Self::PoolChanges
where
Self::PoolChanges: Default,
{
Default::default()
}
fn worst_pool_changes(_num_tranches: Option<u32>) -> Self::PoolChanges;

/// Returns a valid currency to be used in the pool
#[cfg(feature = "runtime-benchmarks")]
Expand All @@ -158,7 +157,7 @@ pub trait PoolMutate<AccountId, PoolId> {

/// Creates the heviest pool possible
#[cfg(feature = "runtime-benchmarks")]
fn create_heaviest_pool(_: PoolId, _: AccountId, _: Self::CurrencyId) {}
fn create_heaviest_pool(_: PoolId, _: AccountId, _: Self::CurrencyId, _num_tranches: u32) {}
}

/// A trait that support pool reserve operations such as withdraw and deposit
Expand Down
24 changes: 17 additions & 7 deletions pallets/pool-registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ use super::*;
fn init_mocks() {
crate::mock::WriteOffPolicy::mock_worst_case_policy(|| ());
crate::mock::WriteOffPolicy::mock_update(|_, _| Ok(()));
crate::mock::PoolSystem::mock_worst_pool_changes(|changes| changes.unwrap_or(0));
crate::mock::PoolSystem::mock_create(|_, _, _, _, _, _, _| Ok(()));
crate::mock::PoolSystem::mock_update(|_, changes| Ok(UpdateState::Stored(changes)));
crate::mock::PoolSystem::mock_execute_update(|_| Ok(0));
}

Expand Down Expand Up @@ -83,26 +85,29 @@ mod benchmarks {
Ok(())
}

/*
#[benchmark]
fn update_no_execution(
n: Linear<1, { min(MaxTranches::<T>::get(), 10) }>,
) -> Result<(), BenchmarkError> {
#[cfg(test)]
init_mocks();

T::ModifyPool::create_heaviest_pool(T::PoolId::default(), whitelisted_caller(), 0.into());
T::ModifyPool::create_heaviest_pool(
T::PoolId::default(),
whitelisted_caller(),
T::CurrencyId::from(0),
n,
);

#[extrinsic_call]
update(
RawOrigin::Signed(whitelisted_caller()),
T::PoolId::default(),
T::ModifyPool::changes(None),
T::ModifyPool::worst_pool_changes(None),
);

Ok(())
}
*/

/*
#[benchmark]
Expand All @@ -125,15 +130,21 @@ mod benchmarks {
}
*/

/*
#[benchmark]
fn execute_update(
n: Linear<1, { min(MaxTranches::<T>::get(), 10) }>,
) -> Result<(), BenchmarkError> {
#[cfg(test)]
init_mocks();

T::ModifyPool::create_heaviest_pool(T::PoolId::default(), whitelisted_caller(), 0.into());
let pool_id = T::PoolId::default();
let currency_id = T::CurrencyId::from(0);

T::ModifyPool::create_heaviest_pool(pool_id, whitelisted_caller(), currency_id, n);
let update_state =
T::ModifyPool::update(pool_id, T::ModifyPool::worst_pool_changes(Some(n))).unwrap();

assert_eq!(update_state, UpdateState::Stored(n));

#[extrinsic_call]
_(
Expand All @@ -143,7 +154,6 @@ mod benchmarks {

Ok(())
}
*/

#[benchmark]
fn set_metadata() -> Result<(), BenchmarkError> {
Expand Down
4 changes: 2 additions & 2 deletions pallets/pool-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pub mod pallet {
///
/// The caller must have the `PoolAdmin` role in order to
/// invoke this extrinsic.
#[pallet::weight(T::WeightInfo::update_no_execution(MaxTranches::<T>::get()))]
#[pallet::weight(T::WeightInfo::update_and_execute(MaxTranches::<T>::get()))]
#[pallet::call_index(1)]
pub fn update(
origin: OriginFor<T>,
Expand Down Expand Up @@ -286,7 +286,7 @@ pub mod pallet {
}
UpdateState::Stored(num_tranches) => {
Self::deposit_event(Event::UpdateStored { pool_id });
T::WeightInfo::update_and_execute(num_tranches)
T::WeightInfo::update_no_execution(num_tranches)
}
};
Ok(Some(weight).into())
Expand Down
2 changes: 1 addition & 1 deletion pallets/pool-registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl cfg_mocks::pools::pallet::Config for Runtime {
impl cfg_mocks::pools::pallet::ConfigMut for Runtime {
type MaxFeesPerPool = ConstU32<5>;
type MaxTranches = ConstU32<5>;
type PoolChanges = ();
type PoolChanges = u32;
type PoolFeeInput = PoolFeeInput<Runtime>;
type TrancheInput = ();
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/pool-registry/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn update_pool() {
assert_ok!(PoolRegistry::update(
RuntimeOrigin::signed(POOL_ADMIN),
POOL_A,
(),
1,
));

System::assert_last_event(Event::<Runtime>::UpdateRegistered { pool_id: POOL_A }.into());
Expand Down
10 changes: 8 additions & 2 deletions pallets/pool-system/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,12 @@ impl<T: Config> PoolMutate<T::AccountId, T::PoolId> for Pallet<T> {
}

#[cfg(feature = "runtime-benchmarks")]
fn create_heaviest_pool(pool_id: T::PoolId, admin: T::AccountId, currency_id: T::CurrencyId) {
fn create_heaviest_pool(
pool_id: T::PoolId,
admin: T::AccountId,
currency_id: T::CurrencyId,
num_tranches: u32,
) {
use sp_runtime::traits::Bounded;

Self::fund_depositor(&admin);
Expand All @@ -442,7 +447,7 @@ impl<T: Config> PoolMutate<T::AccountId, T::PoolId> for Pallet<T> {
admin.clone(),
admin,
pool_id,
Self::worst_tranche_input_list(Self::MaxTranches::get()),
Self::worst_tranche_input_list(num_tranches),
currency_id,
T::Balance::max_value(),
Self::worst_fee_input_list(Self::MaxFeesPerPool::get() - 1),
Expand Down Expand Up @@ -625,6 +630,7 @@ mod benchmarks_utils {
pool_id,
admin.clone(),
T::CurrencyId::from(POOL_CURRENCY_INDEX),
T::MaxTranches::get(),
);
}
}
Expand Down
6 changes: 1 addition & 5 deletions runtime/altair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,11 +1458,7 @@ parameter_types! {
/// The index with which this pallet is instantiated in this runtime.
pub PoolPalletIndex: u8 = <PoolSystem as PalletInfoAccess>::index() as u8;

pub const MinUpdateDelay: u64 = if cfg!(feature = "runtime-benchmarks") {
0
} else {
2 * SECONDS_PER_DAY
};
pub const MinUpdateDelay: u64 = 2 * SECONDS_PER_DAY;

pub const ChallengeTime: BlockNumber = if cfg!(feature = "runtime-benchmarks") {
// Disable challenge time in benchmarks
Expand Down
6 changes: 1 addition & 5 deletions runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1352,11 +1352,7 @@ parameter_types! {
/// The index with which this pallet is instantiated in this runtime.
pub PoolPalletIndex: u8 = <PoolSystem as PalletInfoAccess>::index() as u8;

pub const MinUpdateDelay: u64 = if cfg!(feature = "runtime-benchmarks") {
0 // Disable update delay in benchmarks
} else {
7 * SECONDS_PER_DAY // 7 days notice
};
pub const MinUpdateDelay: u64 = 7 * SECONDS_PER_DAY; // 7 days notice

pub const ChallengeTime: BlockNumber = if cfg!(feature = "runtime-benchmarks") {
0 // Disable challenge time in benchmarks
Expand Down
8 changes: 1 addition & 7 deletions runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,13 +1104,7 @@ parameter_types! {
/// The index with which this pallet is instantiated in this runtime.
pub PoolPalletIndex: u8 = <PoolSystem as PalletInfoAccess>::index() as u8;

pub const MinUpdateDelay: u64 = if cfg!(feature = "runtime-benchmarks") {
// Disable update delay in benchmarks
0
} else {
// Same as Lower bound for epochs.
1
};
pub const MinUpdateDelay: u64 = 1;

pub const ChallengeTime: BlockNumber = if cfg!(feature = "runtime-benchmarks") {
// Disable challenge time in benchmarks
Expand Down

0 comments on commit 4028587

Please sign in to comment.