Benchmark's successful origin api update (#13146)

* try successful origin unimplemented by default

* error as a default impl for try_successful_origin

* remove successful_origin func of EnsureOrigin trait

* default impl -> unimplemented!()

* update EnsureOriginWithArg

* fix EnsureOriginWithArg

* prefix unused arg with underscore

* use try_successful_origin instead successful_origin, map err to Weightless

* fix tests

* remove default impl

* unwrap for indirect origin dep

* replace unwrap by expect with a message

---------

Co-authored-by: parity-processbot <>
This commit is contained in:
Muharem Ismailov
2023-02-01 03:11:41 +01:00
committed by GitHub
parent a46203efb6
commit 3079a17c94
21 changed files with 402 additions and 243 deletions
+87 -29
View File
@@ -18,7 +18,7 @@
//! Preimage pallet benchmarking.
use super::*;
use frame_benchmarking::v1::{account, benchmarks, whitelist_account};
use frame_benchmarking::v1::{account, benchmarks, whitelist_account, BenchmarkError};
use frame_support::assert_ok;
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
@@ -62,7 +62,11 @@ benchmarks! {
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
let (preimage, hash) = sized_preimage_and_hash::<T>(s);
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
assert_ok!(Preimage::<T>::request_preimage(
T::ManagerOrigin::try_successful_origin()
.expect("ManagerOrigin has no successful origin required for the benchmark"),
hash,
));
}: note_preimage(RawOrigin::Signed(caller), preimage)
verify {
assert!(Preimage::<T>::have_preimage(&hash));
@@ -71,9 +75,15 @@ benchmarks! {
note_no_deposit_preimage {
let s in 0 .. MAX_SIZE;
let (preimage, hash) = sized_preimage_and_hash::<T>(s);
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
}: note_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), preimage)
verify {
assert_ok!(Preimage::<T>::request_preimage(
T::ManagerOrigin::try_successful_origin()
.expect("ManagerOrigin has no successful origin required for the benchmark"),
hash,
));
}: note_preimage<T::RuntimeOrigin>(
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
preimage
) verify {
assert!(Preimage::<T>::have_preimage(&hash));
}
@@ -90,9 +100,15 @@ benchmarks! {
// Cheap unnote - will not unreserve since there's no deposit held.
unnote_no_deposit_preimage {
let (preimage, hash) = preimage_and_hash::<T>();
assert_ok!(Preimage::<T>::note_preimage(T::ManagerOrigin::successful_origin(), preimage));
}: unnote_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
verify {
assert_ok!(Preimage::<T>::note_preimage(
T::ManagerOrigin::try_successful_origin()
.expect("ManagerOrigin has no successful origin required for the benchmark"),
preimage,
));
}: unnote_preimage<T::RuntimeOrigin>(
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
hash
) verify {
assert!(!Preimage::<T>::have_preimage(&hash));
}
@@ -102,8 +118,10 @@ benchmarks! {
let noter = funded_account::<T>("noter", 0);
whitelist_account!(noter);
assert_ok!(Preimage::<T>::note_preimage(RawOrigin::Signed(noter.clone()).into(), preimage));
}: _<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
verify {
}: _<T::RuntimeOrigin>(
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
hash
) verify {
let deposit = T::BaseDeposit::get() + T::ByteDeposit::get() * MAX_SIZE.into();
let s = RequestStatus::Requested { deposit: Some((noter, deposit)), count: 1, len: Some(MAX_SIZE) };
assert_eq!(StatusFor::<T>::get(&hash), Some(s));
@@ -111,26 +129,40 @@ benchmarks! {
// Cheap request - would unreserve the deposit but none was held.
request_no_deposit_preimage {
let (preimage, hash) = preimage_and_hash::<T>();
assert_ok!(Preimage::<T>::note_preimage(T::ManagerOrigin::successful_origin(), preimage));
}: request_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
verify {
assert_ok!(Preimage::<T>::note_preimage(
T::ManagerOrigin::try_successful_origin()
.expect("ManagerOrigin has no successful origin required for the benchmark"),
preimage,
));
}: request_preimage<T::RuntimeOrigin>(
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
hash
) verify {
let s = RequestStatus::Requested { deposit: None, count: 2, len: Some(MAX_SIZE) };
assert_eq!(StatusFor::<T>::get(&hash), Some(s));
}
// Cheap request - the preimage is not yet noted, so deposit to unreserve.
request_unnoted_preimage {
let (_, hash) = preimage_and_hash::<T>();
}: request_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
verify {
}: request_preimage<T::RuntimeOrigin>(
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
hash
) verify {
let s = RequestStatus::Requested { deposit: None, count: 1, len: None };
assert_eq!(StatusFor::<T>::get(&hash), Some(s));
}
// Cheap request - the preimage is already requested, so just a counter bump.
request_requested_preimage {
let (_, hash) = preimage_and_hash::<T>();
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
}: request_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
verify {
assert_ok!(Preimage::<T>::request_preimage(
T::ManagerOrigin::try_successful_origin()
.expect("ManagerOrigin has no successful origin required for the benchmark"),
hash,
));
}: request_preimage<T::RuntimeOrigin>(
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
hash
) verify {
let s = RequestStatus::Requested { deposit: None, count: 2, len: None };
assert_eq!(StatusFor::<T>::get(&hash), Some(s));
}
@@ -138,27 +170,53 @@ benchmarks! {
// Expensive unrequest - last reference and it's noted, so will destroy the preimage.
unrequest_preimage {
let (preimage, hash) = preimage_and_hash::<T>();
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
assert_ok!(Preimage::<T>::note_preimage(T::ManagerOrigin::successful_origin(), preimage));
}: _<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
verify {
assert_ok!(Preimage::<T>::request_preimage(
T::ManagerOrigin::try_successful_origin()
.expect("ManagerOrigin has no successful origin required for the benchmark"),
hash,
));
assert_ok!(Preimage::<T>::note_preimage(
T::ManagerOrigin::try_successful_origin()
.expect("ManagerOrigin has no successful origin required for the benchmark"),
preimage,
));
}: _<T::RuntimeOrigin>(
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
hash
) verify {
assert_eq!(StatusFor::<T>::get(&hash), None);
}
// Cheap unrequest - last reference, but it's not noted.
unrequest_unnoted_preimage {
let (_, hash) = preimage_and_hash::<T>();
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
}: unrequest_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
verify {
assert_ok!(Preimage::<T>::request_preimage(
T::ManagerOrigin::try_successful_origin()
.expect("ManagerOrigin has no successful origin required for the benchmark"),
hash,
));
}: unrequest_preimage<T::RuntimeOrigin>(
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
hash
) verify {
assert_eq!(StatusFor::<T>::get(&hash), None);
}
// Cheap unrequest - not the last reference.
unrequest_multi_referenced_preimage {
let (_, hash) = preimage_and_hash::<T>();
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
assert_ok!(Preimage::<T>::request_preimage(T::ManagerOrigin::successful_origin(), hash));
}: unrequest_preimage<T::RuntimeOrigin>(T::ManagerOrigin::successful_origin(), hash)
verify {
assert_ok!(Preimage::<T>::request_preimage(
T::ManagerOrigin::try_successful_origin()
.expect("ManagerOrigin has no successful origin required for the benchmark"),
hash,
));
assert_ok!(Preimage::<T>::request_preimage(
T::ManagerOrigin::try_successful_origin()
.expect("ManagerOrigin has no successful origin required for the benchmark"),
hash,
));
}: unrequest_preimage<T::RuntimeOrigin>(
T::ManagerOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?,
hash
) verify {
let s = RequestStatus::Requested { deposit: None, count: 1, len: None };
assert_eq!(StatusFor::<T>::get(&hash), Some(s));
}