Skip to content

Commit

Permalink
Merge branch 'main' into fix-docs-deploy-ghpages
Browse files Browse the repository at this point in the history
  • Loading branch information
wischli authored Jan 10, 2024
2 parents ac1a57c + 433211e commit 99785e9
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 297 deletions.
68 changes: 25 additions & 43 deletions pallets/oracle-collection/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use cfg_traits::{benchmarking::PoolBenchmarkHelper, changes::ChangeGuard, ValueProvider};
use cfg_traits::{
benchmarking::PoolBenchmarkHelper, changes::ChangeGuard, data::DataRegistry, ValueProvider,
};
use frame_benchmarking::{v2::*, whitelisted_caller};
use frame_system::RawOrigin;

Expand All @@ -23,8 +25,7 @@ fn init_mocks() {
mod util {
use super::*;

pub fn last_change_id_for<T>(
key: T::OracleKey,
pub fn emulate_collection_id_change<T>(
feeders: impl IntoIterator<Item = T::FeederId>,
) -> T::Hash
where
Expand All @@ -36,7 +37,11 @@ mod util {
// Emulate to note a change to later apply it
T::ChangeGuard::note(
T::CollectionId::default(),
Change::<T>::Feeders(key, feeders).into(),
Change::<T>::CollectionInfo(CollectionInfo {
feeders,
..Default::default()
})
.into(),
)
.unwrap()
}
Expand All @@ -56,29 +61,31 @@ mod benchmarks {
use super::*;

#[benchmark]
fn propose_update_feeders(n: Linear<1, 10>) -> Result<(), BenchmarkError> {
fn propose_update_collection_info(n: Linear<1, 10>) -> Result<(), BenchmarkError> {
#[cfg(test)]
init_mocks();

let admin: T::AccountId = whitelisted_caller();

T::ChangeGuard::bench_create_pool(T::CollectionId::default(), &admin);

let feeders = crate::util::feeders_from((0..n).map(Into::into)).unwrap();
let feeders = crate::util::feeders_from((0..n).map(Into::into))?;

#[extrinsic_call]
propose_update_feeders(
propose_update_collection_info(
RawOrigin::Signed(admin),
T::CollectionId::default(),
T::OracleKey::default(),
feeders,
CollectionInfo {
feeders,
..Default::default()
},
);

Ok(())
}

#[benchmark]
fn apply_update_feeders(n: Linear<1, 10>) -> Result<(), BenchmarkError> {
fn apply_update_collection_info(n: Linear<1, 10>) -> Result<(), BenchmarkError> {
#[cfg(test)]
init_mocks();

Expand All @@ -87,12 +94,12 @@ mod benchmarks {
T::ChangeGuard::bench_create_pool(T::CollectionId::default(), &admin);

let feeder_ids = (0..n).map(Into::into);
let feeders = crate::util::feeders_from::<_, T::MaxFeedersPerKey>(feeder_ids).unwrap();
let feeders = crate::util::feeders_from::<_, T::MaxFeedersPerKey>(feeder_ids)?;

let change_id = util::last_change_id_for::<T>(T::OracleKey::default(), feeders);
let change_id = util::emulate_collection_id_change::<T>(feeders);

#[extrinsic_call]
apply_update_feeders(
apply_update_collection_info(
RawOrigin::Signed(admin),
T::CollectionId::default(),
change_id,
Expand All @@ -111,7 +118,7 @@ mod benchmarks {
T::ChangeGuard::bench_create_pool(T::CollectionId::default(), &admin);

let feeder_ids = (0..n).map(Into::<T::FeederId>::into);
let feeders = crate::util::feeders_from::<_, T::MaxFeedersPerKey>(feeder_ids).unwrap();
let feeders = crate::util::feeders_from::<_, T::MaxFeedersPerKey>(feeder_ids)?;

// n feeders using m keys
for k in 0..m {
Expand All @@ -125,20 +132,14 @@ mod benchmarks {
);
}

Pallet::<T>::apply_update_feeders(
RawOrigin::Signed(admin.clone()).into(),
T::CollectionId::default(),
util::last_change_id_for::<T>(key, feeders.clone()),
)?;
Pallet::<T>::register_id(&k.into(), &T::CollectionId::default())?;
}

// Worst case expect to read the max age
Pallet::<T>::set_collection_info(
Pallet::<T>::apply_update_collection_info(
RawOrigin::Signed(admin.clone()).into(),
T::CollectionId::default(),
CollectionInfo::default(),
)
.unwrap();
util::emulate_collection_id_change::<T>(feeders.clone()),
)?;

#[extrinsic_call]
update_collection(RawOrigin::Signed(admin), T::CollectionId::default());
Expand All @@ -153,24 +154,5 @@ mod benchmarks {
Ok(())
}

#[benchmark]
fn set_collection_info() -> Result<(), BenchmarkError> {
#[cfg(test)]
init_mocks();

let admin: T::AccountId = whitelisted_caller();

T::ChangeGuard::bench_create_pool(T::CollectionId::default(), &admin);

#[extrinsic_call]
set_collection_info(
RawOrigin::Signed(admin),
T::CollectionId::default(),
CollectionInfo::default(),
);

Ok(())
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Runtime);
}
Loading

0 comments on commit 99785e9

Please sign in to comment.