Skip to content

Commit

Permalink
Properly declare #[pallet::validate_unsigned] in ParachainSystem (par…
Browse files Browse the repository at this point in the history
…itytech#537)

* Properly declare #[pallet::validate_unsigned] in ParachainSystem

* Add ValidateUnsigned to construct_runtime in ParachainSystem tests
  • Loading branch information
KiChjang authored Jul 15, 2021
1 parent 59cdbb6 commit 303b194
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
45 changes: 23 additions & 22 deletions pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,29 @@ pub mod pallet {
sp_io::storage::set(b":c", &[]);
}
}

#[pallet::validate_unsigned]
impl<T: Config> sp_runtime::traits::ValidateUnsigned for Pallet<T> {
type Call = Call<T>;

fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
if let Call::enact_authorized_upgrade(ref code) = call {
if let Ok(hash) = Self::validate_authorized_upgrade(code) {
return Ok(ValidTransaction {
priority: 100,
requires: vec![],
provides: vec![hash.as_ref().to_vec()],
longevity: TransactionLongevity::max_value(),
propagate: true,
});
}
}
if let Call::set_validation_data(..) = call {
return Ok(Default::default());
}
Err(InvalidTransaction::Call.into())
}
}
}

impl<T: Config> Pallet<T> {
Expand All @@ -606,28 +629,6 @@ impl<T: Config> Pallet<T> {
}
}

impl<T: Config> sp_runtime::traits::ValidateUnsigned for Pallet<T> {
type Call = Call<T>;

fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
if let Call::enact_authorized_upgrade(ref code) = call {
if let Ok(hash) = Self::validate_authorized_upgrade(code) {
return Ok(ValidTransaction {
priority: 100,
requires: vec![],
provides: vec![hash.as_ref().to_vec()],
longevity: TransactionLongevity::max_value(),
propagate: true,
});
}
}
if let Call::set_validation_data(..) = call {
return Ok(Default::default());
}
Err(InvalidTransaction::Call.into())
}
}

impl<T: Config> GetChannelInfo for Pallet<T> {
fn get_channel_status(id: ParaId) -> ChannelStatus {
// Note, that we are using `relevant_messaging_state` which may be from the previous
Expand Down
2 changes: 1 addition & 1 deletion pallets/parachain-system/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ frame_support::construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
ParachainSystem: parachain_system::{Pallet, Call, Storage, Event<T>},
ParachainSystem: parachain_system::{Pallet, Call, Storage, Event<T>, ValidateUnsigned},
}
);

Expand Down

0 comments on commit 303b194

Please sign in to comment.