Associated type Hasher for QueryPreimage, StorePreimage and Bounded (#1720)

I hope it's enough to fix #1701 
the only solution I found to make it happen is to put an associated type
to the `Bounded` enum as well.
@liamaharon @kianenigma @bkchr 

Polkadot address: 12poSUQPtcF1HUPQGY3zZu2P8emuW9YnsPduA4XG3oCEfJVp

---------

Signed-off-by: muraca <mmuraca247@gmail.com>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Matteo Muraca
2023-09-27 14:46:14 +02:00
committed by GitHub
parent 7cbe0c76ef
commit 8b061a5c5d
20 changed files with 189 additions and 159 deletions
@@ -82,13 +82,13 @@ fn make_task<T: Config>(
Scheduled { maybe_id, priority, call, maybe_periodic, origin, _phantom: PhantomData }
}
fn bounded<T: Config>(len: u32) -> Option<Bounded<<T as Config>::RuntimeCall>> {
fn bounded<T: Config>(len: u32) -> Option<BoundedCallOf<T>> {
let call =
<<T as Config>::RuntimeCall>::from(SystemCall::remark { remark: vec![0; len as usize] });
T::Preimages::bound(call).ok()
}
fn make_call<T: Config>(maybe_lookup_len: Option<u32>) -> Bounded<<T as Config>::RuntimeCall> {
fn make_call<T: Config>(maybe_lookup_len: Option<u32>) -> BoundedCallOf<T> {
let bound = BoundedInline::bound() as u32;
let mut len = match maybe_lookup_len {
Some(len) => len.min(T::Preimages::MAX_LENGTH as u32 - 2).max(bound) - 3,
+20 -15
View File
@@ -91,8 +91,8 @@ use frame_support::{
ensure,
traits::{
schedule::{self, DispatchTime, MaybeHashed},
Bounded, CallerTrait, EnsureOrigin, Get, Hash as PreimageHash, IsType, OriginTrait,
PalletInfoAccess, PrivilegeCmp, QueryPreimage, StorageVersion, StorePreimage,
Bounded, CallerTrait, EnsureOrigin, Get, IsType, OriginTrait, PalletInfoAccess,
PrivilegeCmp, QueryPreimage, StorageVersion, StorePreimage,
},
weights::{Weight, WeightMeter},
};
@@ -119,6 +119,9 @@ pub type TaskAddress<BlockNumber> = (BlockNumber, u32);
pub type CallOrHashOf<T> =
MaybeHashed<<T as Config>::RuntimeCall, <T as frame_system::Config>::Hash>;
pub type BoundedCallOf<T> =
Bounded<<T as Config>::RuntimeCall, <T as frame_system::Config>::Hashing>;
#[cfg_attr(any(feature = "std", test), derive(PartialEq, Eq))]
#[derive(Clone, RuntimeDebug, Encode, Decode)]
struct ScheduledV1<Call, BlockNumber> {
@@ -165,7 +168,7 @@ pub type ScheduledV3Of<T> = ScheduledV3<
pub type ScheduledOf<T> = Scheduled<
TaskName,
Bounded<<T as Config>::RuntimeCall>,
BoundedCallOf<T>,
BlockNumberFor<T>,
<T as Config>::PalletsOrigin,
<T as frame_system::Config>::AccountId,
@@ -254,7 +257,7 @@ pub mod pallet {
type WeightInfo: WeightInfo;
/// The preimage provider with which we look up call hashes to get the call.
type Preimages: QueryPreimage + StorePreimage;
type Preimages: QueryPreimage<H = Self::Hashing> + StorePreimage;
}
#[pallet::storage]
@@ -440,7 +443,7 @@ pub mod pallet {
}
}
impl<T: Config<Hash = PreimageHash>> Pallet<T> {
impl<T: Config> Pallet<T> {
/// Migrate storage format from V1 to V4.
///
/// Returns the weight consumed by this migration.
@@ -627,7 +630,7 @@ impl<T: Config<Hash = PreimageHash>> Pallet<T> {
>(&bounded)
{
log::error!(
"Dropping undecodable call {}: {:?}",
"Dropping undecodable call {:?}: {:?}",
&h,
&err
);
@@ -695,7 +698,7 @@ impl<T: Config> Pallet<T> {
Option<
Scheduled<
TaskName,
Bounded<<T as Config>::RuntimeCall>,
BoundedCallOf<T>,
BlockNumberFor<T>,
OldOrigin,
T::AccountId,
@@ -797,7 +800,7 @@ impl<T: Config> Pallet<T> {
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
priority: schedule::Priority,
origin: T::PalletsOrigin,
call: Bounded<<T as Config>::RuntimeCall>,
call: BoundedCallOf<T>,
) -> Result<TaskAddress<BlockNumberFor<T>>, DispatchError> {
let when = Self::resolve_time(when)?;
@@ -886,7 +889,7 @@ impl<T: Config> Pallet<T> {
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
priority: schedule::Priority,
origin: T::PalletsOrigin,
call: Bounded<<T as Config>::RuntimeCall>,
call: BoundedCallOf<T>,
) -> Result<TaskAddress<BlockNumberFor<T>>, DispatchError> {
// ensure id it is unique
if Lookup::<T>::contains_key(&id) {
@@ -1191,8 +1194,8 @@ impl<T: Config> Pallet<T> {
}
}
impl<T: Config<Hash = PreimageHash>>
schedule::v2::Anon<BlockNumberFor<T>, <T as Config>::RuntimeCall, T::PalletsOrigin> for Pallet<T>
impl<T: Config> schedule::v2::Anon<BlockNumberFor<T>, <T as Config>::RuntimeCall, T::PalletsOrigin>
for Pallet<T>
{
type Address = TaskAddress<BlockNumberFor<T>>;
type Hash = T::Hash;
@@ -1225,8 +1228,8 @@ impl<T: Config<Hash = PreimageHash>>
}
}
impl<T: Config<Hash = PreimageHash>>
schedule::v2::Named<BlockNumberFor<T>, <T as Config>::RuntimeCall, T::PalletsOrigin> for Pallet<T>
impl<T: Config> schedule::v2::Named<BlockNumberFor<T>, <T as Config>::RuntimeCall, T::PalletsOrigin>
for Pallet<T>
{
type Address = TaskAddress<BlockNumberFor<T>>;
type Hash = T::Hash;
@@ -1270,13 +1273,14 @@ impl<T: Config> schedule::v3::Anon<BlockNumberFor<T>, <T as Config>::RuntimeCall
for Pallet<T>
{
type Address = TaskAddress<BlockNumberFor<T>>;
type Hasher = T::Hashing;
fn schedule(
when: DispatchTime<BlockNumberFor<T>>,
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
priority: schedule::Priority,
origin: T::PalletsOrigin,
call: Bounded<<T as Config>::RuntimeCall>,
call: BoundedCallOf<T>,
) -> Result<Self::Address, DispatchError> {
Self::do_schedule(when, maybe_periodic, priority, origin, call)
}
@@ -1308,6 +1312,7 @@ impl<T: Config> schedule::v3::Named<BlockNumberFor<T>, <T as Config>::RuntimeCal
for Pallet<T>
{
type Address = TaskAddress<BlockNumberFor<T>>;
type Hasher = T::Hashing;
fn schedule_named(
id: TaskName,
@@ -1315,7 +1320,7 @@ impl<T: Config> schedule::v3::Named<BlockNumberFor<T>, <T as Config>::RuntimeCal
maybe_periodic: Option<schedule::Period<BlockNumberFor<T>>>,
priority: schedule::Priority,
origin: T::PalletsOrigin,
call: Bounded<<T as Config>::RuntimeCall>,
call: BoundedCallOf<T>,
) -> Result<Self::Address, DispatchError> {
Self::do_schedule_named(id, when, maybe_periodic, priority, origin, call)
}
+1 -1
View File
@@ -83,7 +83,7 @@ pub mod v3 {
/// Migrate the scheduler pallet from V3 to V4.
pub struct MigrateToV4<T>(sp_std::marker::PhantomData<T>);
impl<T: Config<Hash = PreimageHash>> OnRuntimeUpgrade for MigrateToV4<T> {
impl<T: Config> OnRuntimeUpgrade for MigrateToV4<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
ensure!(StorageVersion::get::<Pallet<T>>() == 3, "Can only upgrade from version 3");
+1 -1
View File
@@ -1019,7 +1019,7 @@ fn test_migrate_origin() {
new_test_ext().execute_with(|| {
for i in 0..3u64 {
let k = i.twox_64_concat();
let old: Vec<Option<Scheduled<[u8; 32], Bounded<RuntimeCall>, u64, u32, u64>>> = vec![
let old: Vec<Option<Scheduled<[u8; 32], BoundedCallOf<Test>, u64, u32, u64>>> = vec![
Some(Scheduled {
maybe_id: None,
priority: i as u8 + 10,