mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 03:18:01 +00:00
Emit error when construct_runtime imports a non-existent pallet part (#8949)
* Emit error when construct_runtime imports a non-existent Call part * Reword and display pallet name when emitting part not found error * Migrate decl_outer_dispatch to a proc macro * Rename calls.rs to call.rs * Create new construct_runtime_v2 macro * Add UI test for importing non-existent call part in construct_runtime * Emit error when construct_runtime imports a non-existent Config part * Emit error when construct_runtime imports a non-existent Event part * Migrate decl_outer_inherent to a proc macro * Emit error when construct_runtime imports a non-existent Inherent part * Migrate decl_outer_validate_unsigned to a proc macro * Emit error when construct_runtime imports a non-existent ValidateUnsigned part * impl for old macro * fix line width * add doc * hide macroes and use unique counter everywhere * Remove construct_runtime_v2 * Encapsulate pallet part check macros in a module * Fix macro definitions in dummy part checker * Tag ProvideInherent impl with #[pallet::inherent] properly for authorship pallet * Remove Call part from pallets that do not define it * Add Call part unit tests * Remove undefined Call part import from offences pallet * Add tests for expand_outer_inherent * Remove Call part from pallets that do not define them * Remove Call part imports from pallets that do not have it defined * Remove Call part import of the offences pallet from grandpa pallet mocks * Update frame/support/test/tests/pallet.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Remove Call part imports for pallets that do not define them * Move inherent tests to inherent_expand * Add unit tests for expand_outer_validate_unsigned * Add newline at the end of file * fix ui test * Small prayer to RNGsus for fixing CI * Remove Call part from construct_runtime for randomness collective flip pallet * Remove Call part import for randomness collective flip pallet * Summon Laplace's demon instead of praying to RNGsus * Update test expectations * fix ui test and make sure it's flaky * Revert "fix ui test and make sure it's flaky" This reverts commit 362b6881389c911ef8d9ef85d71c9463f5694b20. * Comment out test instead of putting it in conditional compilation * Update UI test expectations * Update UI test expectations * Emit error when construct_runtime imports a non-existent Origin part Co-authored-by: thiolliere <gui.thiolliere@gmail.com> Co-authored-by: Denis P <denis.pisarev@parity.io>
This commit is contained in:
@@ -24,7 +24,6 @@
|
||||
use sp_std::{result, prelude::*, collections::btree_set::BTreeSet};
|
||||
use frame_support::{
|
||||
dispatch, traits::{FindAuthor, VerifySeal, Get},
|
||||
inherent::{InherentData, ProvideInherent, InherentIdentifier},
|
||||
};
|
||||
use codec::{Encode, Decode};
|
||||
use sp_runtime::traits::{Header as HeaderT, One, Saturating};
|
||||
@@ -238,6 +237,68 @@ pub mod pallet {
|
||||
Self::verify_and_import_uncles(new_uncles)
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::inherent]
|
||||
impl<T: Config> ProvideInherent for Pallet<T> {
|
||||
type Call = Call<T>;
|
||||
type Error = InherentError;
|
||||
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
|
||||
|
||||
fn create_inherent(data: &InherentData) -> Option<Self::Call> {
|
||||
let uncles = data.uncles().unwrap_or_default();
|
||||
let mut set_uncles = Vec::new();
|
||||
|
||||
if !uncles.is_empty() {
|
||||
let prev_uncles = <Uncles<T>>::get();
|
||||
let mut existing_hashes: Vec<_> = prev_uncles.into_iter().filter_map(|entry|
|
||||
match entry {
|
||||
UncleEntryItem::InclusionHeight(_) => None,
|
||||
UncleEntryItem::Uncle(h, _) => Some(h),
|
||||
}
|
||||
).collect();
|
||||
|
||||
let mut acc: <T::FilterUncle as FilterUncle<_, _>>::Accumulator = Default::default();
|
||||
|
||||
for uncle in uncles {
|
||||
match Self::verify_uncle(&uncle, &existing_hashes, &mut acc) {
|
||||
Ok(_) => {
|
||||
let hash = uncle.hash();
|
||||
set_uncles.push(uncle);
|
||||
existing_hashes.push(hash);
|
||||
|
||||
if set_uncles.len() == MAX_UNCLES {
|
||||
break
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// skip this uncle
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if set_uncles.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(Call::set_uncles(set_uncles))
|
||||
}
|
||||
}
|
||||
|
||||
fn check_inherent(call: &Self::Call, _data: &InherentData) -> result::Result<(), Self::Error> {
|
||||
match call {
|
||||
Call::set_uncles(ref uncles) if uncles.len() > MAX_UNCLES => {
|
||||
Err(InherentError::Uncles(Error::<T>::TooManyUncles.as_str().into()))
|
||||
},
|
||||
_ => {
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn is_inherent(call: &Self::Call) -> bool {
|
||||
matches!(call, Call::set_uncles(_))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
@@ -348,67 +409,6 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> ProvideInherent for Pallet<T> {
|
||||
type Call = Call<T>;
|
||||
type Error = InherentError;
|
||||
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
|
||||
|
||||
fn create_inherent(data: &InherentData) -> Option<Self::Call> {
|
||||
let uncles = data.uncles().unwrap_or_default();
|
||||
let mut set_uncles = Vec::new();
|
||||
|
||||
if !uncles.is_empty() {
|
||||
let prev_uncles = <Uncles<T>>::get();
|
||||
let mut existing_hashes: Vec<_> = prev_uncles.into_iter().filter_map(|entry|
|
||||
match entry {
|
||||
UncleEntryItem::InclusionHeight(_) => None,
|
||||
UncleEntryItem::Uncle(h, _) => Some(h),
|
||||
}
|
||||
).collect();
|
||||
|
||||
let mut acc: <T::FilterUncle as FilterUncle<_, _>>::Accumulator = Default::default();
|
||||
|
||||
for uncle in uncles {
|
||||
match Self::verify_uncle(&uncle, &existing_hashes, &mut acc) {
|
||||
Ok(_) => {
|
||||
let hash = uncle.hash();
|
||||
set_uncles.push(uncle);
|
||||
existing_hashes.push(hash);
|
||||
|
||||
if set_uncles.len() == MAX_UNCLES {
|
||||
break
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// skip this uncle
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if set_uncles.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(Call::set_uncles(set_uncles))
|
||||
}
|
||||
}
|
||||
|
||||
fn check_inherent(call: &Self::Call, _data: &InherentData) -> result::Result<(), Self::Error> {
|
||||
match call {
|
||||
Call::set_uncles(ref uncles) if uncles.len() > MAX_UNCLES => {
|
||||
Err(InherentError::Uncles(Error::<T>::TooManyUncles.as_str().into()))
|
||||
},
|
||||
_ => {
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn is_inherent(call: &Self::Call) -> bool {
|
||||
matches!(call, Call::set_uncles(_))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate as pallet_authorship;
|
||||
|
||||
Reference in New Issue
Block a user