mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 11:17:56 +00:00
Moves Block to frame_system instead of construct_runtime and removes Header and BlockNumber (#14437)
* Initial setup * Adds node block * Uses UncheckedExtrinsic and removes Where section * Updates frame_system to use Block * Adds deprecation warning * Fixes pallet-timestamp * Removes Header and BlockNumber * Addresses review comments * Addresses review comments * Adds comment about compiler bug * Removes where clause * Refactors code * Fixes errors in cargo check * Fixes errors in cargo check * Fixes warnings in cargo check * Formatting * Fixes construct_runtime tests * Uses import instead of full path for BlockNumber * Uses import instead of full path for Header * Formatting * Fixes construct_runtime tests * Fixes imports in benchmarks * Formatting * Fixes construct_runtime tests * Formatting * Minor updates * Fixes construct_runtime ui tests * Fixes construct_runtime ui tests with 1.70 * Fixes docs * Fixes docs * Adds u128 mock block type * Fixes split example * fixes for cumulus * ".git/.scripts/commands/fmt/fmt.sh" * Updates new tests * Fixes fully-qualified path in few places * Formatting * Update frame/examples/default-config/src/lib.rs Co-authored-by: Juan <juangirini@gmail.com> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Juan <juangirini@gmail.com> * ".git/.scripts/commands/fmt/fmt.sh" * Addresses some review comments * Fixes build * ".git/.scripts/commands/fmt/fmt.sh" * Update frame/democracy/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/democracy/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update frame/support/procedural/src/construct_runtime/mod.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Addresses review comments * Updates trait bounds * Minor fix * ".git/.scripts/commands/fmt/fmt.sh" * Removes unnecessary bound * ".git/.scripts/commands/fmt/fmt.sh" * Updates test * Fixes build * Adds a bound for header * ".git/.scripts/commands/fmt/fmt.sh" * Removes where block * Minor fix * Minor fix * Fixes tests * ".git/.scripts/commands/update-ui/update-ui.sh" 1.70 * Updates test * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Updates doc * Updates doc --------- Co-authored-by: command-bot <> Co-authored-by: Juan <juangirini@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{Config, Pallet};
|
||||
use crate::{pallet_prelude::BlockNumberFor, Config, Pallet};
|
||||
use codec::{Decode, Encode};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
@@ -60,7 +60,7 @@ impl<T: Config + Send + Sync> SignedExtension for CheckGenesis<T> {
|
||||
const IDENTIFIER: &'static str = "CheckGenesis";
|
||||
|
||||
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
|
||||
Ok(<Pallet<T>>::block_hash(T::BlockNumber::zero()))
|
||||
Ok(<Pallet<T>>::block_hash(BlockNumberFor::<T>::zero()))
|
||||
}
|
||||
|
||||
fn pre_dispatch(
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::{BlockHash, Config, Pallet};
|
||||
use crate::{pallet_prelude::BlockNumberFor, BlockHash, Config, Pallet};
|
||||
use codec::{Decode, Encode};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
@@ -78,7 +78,7 @@ impl<T: Config + Send + Sync> SignedExtension for CheckMortality<T> {
|
||||
|
||||
fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
|
||||
let current_u64 = <Pallet<T>>::block_number().saturated_into::<u64>();
|
||||
let n = self.0.birth(current_u64).saturated_into::<T::BlockNumber>();
|
||||
let n = self.0.birth(current_u64).saturated_into::<BlockNumberFor<T>>();
|
||||
if !<BlockHash<T>>::contains_key(n) {
|
||||
Err(InvalidTransaction::AncientBirthBlock.into())
|
||||
} else {
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use pallet_prelude::{BlockNumberFor, HeaderFor};
|
||||
#[cfg(feature = "std")]
|
||||
use serde::Serialize;
|
||||
use sp_io::hashing::blake2_256;
|
||||
@@ -72,9 +73,9 @@ use sp_runtime::traits::TrailingZeroInput;
|
||||
use sp_runtime::{
|
||||
generic,
|
||||
traits::{
|
||||
self, AtLeast32Bit, AtLeast32BitUnsigned, BadOrigin, BlockNumberProvider, Bounded,
|
||||
CheckEqual, Dispatchable, Hash, Lookup, LookupError, MaybeDisplay,
|
||||
MaybeSerializeDeserialize, Member, One, Saturating, SimpleBitOps, StaticLookup, Zero,
|
||||
self, AtLeast32Bit, BadOrigin, BlockNumberProvider, Bounded, CheckEqual, Dispatchable,
|
||||
Hash, Header, Lookup, LookupError, MaybeDisplay, MaybeSerializeDeserialize, Member, One,
|
||||
Saturating, SimpleBitOps, StaticLookup, Zero,
|
||||
},
|
||||
DispatchError, RuntimeDebug,
|
||||
};
|
||||
@@ -217,13 +218,10 @@ pub mod pallet {
|
||||
#[frame_support::register_default_impl(TestDefaultConfig)]
|
||||
impl DefaultConfig for TestDefaultConfig {
|
||||
type Index = u32;
|
||||
type BlockNumber = u32;
|
||||
type Header = sp_runtime::generic::Header<Self::BlockNumber, Self::Hashing>;
|
||||
type Hash = sp_core::hash::H256;
|
||||
type Hashing = sp_runtime::traits::BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = sp_runtime::traits::IdentityLookup<u64>;
|
||||
type BlockHashCount = frame_support::traits::ConstU32<10>;
|
||||
type MaxConsumers = frame_support::traits::ConstU32<16>;
|
||||
type AccountData = ();
|
||||
type OnNewAccount = ();
|
||||
@@ -287,21 +285,6 @@ pub mod pallet {
|
||||
+ Copy
|
||||
+ MaxEncodedLen;
|
||||
|
||||
/// The block number type used by the runtime.
|
||||
type BlockNumber: Parameter
|
||||
+ Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug
|
||||
+ MaybeDisplay
|
||||
+ AtLeast32BitUnsigned
|
||||
+ Default
|
||||
+ Bounded
|
||||
+ Copy
|
||||
+ sp_std::hash::Hash
|
||||
+ sp_std::str::FromStr
|
||||
+ MaxEncodedLen
|
||||
+ TypeInfo;
|
||||
|
||||
/// The output of the `Hashing` function.
|
||||
type Hash: Parameter
|
||||
+ Member
|
||||
@@ -338,12 +321,15 @@ pub mod pallet {
|
||||
/// functional/efficient alternatives.
|
||||
type Lookup: StaticLookup<Target = Self::AccountId>;
|
||||
|
||||
/// The block header.
|
||||
type Header: Parameter + traits::Header<Number = Self::BlockNumber, Hash = Self::Hash>;
|
||||
/// The Block type used by the runtime. This is used by `construct_runtime` to retrieve the
|
||||
/// extrinsics or other block specific data as needed.
|
||||
#[pallet::no_default]
|
||||
type Block: Parameter + Member + traits::Block<Hash = Self::Hash>;
|
||||
|
||||
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
|
||||
#[pallet::constant]
|
||||
type BlockHashCount: Get<Self::BlockNumber>;
|
||||
#[pallet::no_default]
|
||||
type BlockHashCount: Get<BlockNumberFor<Self>>;
|
||||
|
||||
/// The weight of runtime database operations the runtime can invoke.
|
||||
#[pallet::constant]
|
||||
@@ -590,7 +576,7 @@ pub mod pallet {
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn block_hash)]
|
||||
pub type BlockHash<T: Config> =
|
||||
StorageMap<_, Twox64Concat, T::BlockNumber, T::Hash, ValueQuery>;
|
||||
StorageMap<_, Twox64Concat, BlockNumberFor<T>, T::Hash, ValueQuery>;
|
||||
|
||||
/// Extrinsics data for the current block (maps an extrinsic's index to its data).
|
||||
#[pallet::storage]
|
||||
@@ -603,7 +589,7 @@ pub mod pallet {
|
||||
#[pallet::storage]
|
||||
#[pallet::whitelist_storage]
|
||||
#[pallet::getter(fn block_number)]
|
||||
pub(super) type Number<T: Config> = StorageValue<_, T::BlockNumber, ValueQuery>;
|
||||
pub(super) type Number<T: Config> = StorageValue<_, BlockNumberFor<T>, ValueQuery>;
|
||||
|
||||
/// Hash of the previous block.
|
||||
#[pallet::storage]
|
||||
@@ -642,14 +628,14 @@ pub mod pallet {
|
||||
/// allows light-clients to leverage the changes trie storage tracking mechanism and
|
||||
/// in case of changes fetch the list of events of interest.
|
||||
///
|
||||
/// The value has the type `(T::BlockNumber, EventIndex)` because if we used only just
|
||||
/// The value has the type `(BlockNumberFor<T>, EventIndex)` because if we used only just
|
||||
/// the `EventIndex` then in case if the topic has the same contents on the next block
|
||||
/// no notification will be triggered thus the event might be lost.
|
||||
#[pallet::storage]
|
||||
#[pallet::unbounded]
|
||||
#[pallet::getter(fn event_topics)]
|
||||
pub(super) type EventTopics<T: Config> =
|
||||
StorageMap<_, Blake2_128Concat, T::Hash, Vec<(T::BlockNumber, EventIndex)>, ValueQuery>;
|
||||
StorageMap<_, Blake2_128Concat, T::Hash, Vec<(BlockNumberFor<T>, EventIndex)>, ValueQuery>;
|
||||
|
||||
/// Stores the `spec_version` and `spec_name` of when the last runtime upgrade happened.
|
||||
#[pallet::storage]
|
||||
@@ -682,7 +668,7 @@ pub mod pallet {
|
||||
#[pallet::genesis_build]
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
fn build(&self) {
|
||||
<BlockHash<T>>::insert::<_, T::Hash>(T::BlockNumber::zero(), hash69());
|
||||
<BlockHash<T>>::insert::<_, T::Hash>(BlockNumberFor::<T>::zero(), hash69());
|
||||
<ParentHash<T>>::put::<T::Hash>(hash69());
|
||||
<LastRuntimeUpgrade<T>>::put(LastRuntimeUpgradeInfo::from(T::Version::get()));
|
||||
<UpgradedToU32RefCount<T>>::put(true);
|
||||
@@ -1370,7 +1356,7 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
/// Start the execution of a particular block.
|
||||
pub fn initialize(number: &T::BlockNumber, parent_hash: &T::Hash, digest: &generic::Digest) {
|
||||
pub fn initialize(number: &BlockNumberFor<T>, parent_hash: &T::Hash, digest: &generic::Digest) {
|
||||
// populate environment
|
||||
ExecutionPhase::<T>::put(Phase::Initialization);
|
||||
storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &0u32);
|
||||
@@ -1387,7 +1373,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Remove temporary "environment" entries in storage, compute the storage root and return the
|
||||
/// resulting header for this block.
|
||||
pub fn finalize() -> T::Header {
|
||||
pub fn finalize() -> HeaderFor<T> {
|
||||
log::debug!(
|
||||
target: LOG_TARGET,
|
||||
"[{:?}] {} extrinsics, length: {} (normal {}%, op: {}%, mandatory {}%) / normal weight:\
|
||||
@@ -1459,13 +1445,7 @@ impl<T: Config> Pallet<T> {
|
||||
let storage_root = T::Hash::decode(&mut &sp_io::storage::root(version)[..])
|
||||
.expect("Node is configured to use the same hash; qed");
|
||||
|
||||
<T::Header as traits::Header>::new(
|
||||
number,
|
||||
extrinsics_root,
|
||||
storage_root,
|
||||
parent_hash,
|
||||
digest,
|
||||
)
|
||||
HeaderFor::<T>::new(number, extrinsics_root, storage_root, parent_hash, digest)
|
||||
}
|
||||
|
||||
/// Deposits a log and ensures it matches the block's log data.
|
||||
@@ -1478,8 +1458,8 @@ impl<T: Config> Pallet<T> {
|
||||
pub fn externalities() -> TestExternalities {
|
||||
TestExternalities::new(sp_core::storage::Storage {
|
||||
top: map![
|
||||
<BlockHash<T>>::hashed_key_for(T::BlockNumber::zero()) => [69u8; 32].encode(),
|
||||
<Number<T>>::hashed_key().to_vec() => T::BlockNumber::one().encode(),
|
||||
<BlockHash<T>>::hashed_key_for(BlockNumberFor::<T>::zero()) => [69u8; 32].encode(),
|
||||
<Number<T>>::hashed_key().to_vec() => BlockNumberFor::<T>::one().encode(),
|
||||
<ParentHash<T>>::hashed_key().to_vec() => [69u8; 32].encode()
|
||||
],
|
||||
children_default: map![],
|
||||
@@ -1524,7 +1504,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// Set the block number to something in particular. Can be used as an alternative to
|
||||
/// `initialize` for tests that don't need to bother with the other environment entries.
|
||||
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
|
||||
pub fn set_block_number(n: T::BlockNumber) {
|
||||
pub fn set_block_number(n: BlockNumberFor<T>) {
|
||||
<Number<T>>::put(n);
|
||||
}
|
||||
|
||||
@@ -1742,7 +1722,7 @@ impl<T: Config> HandleLifetime<T::AccountId> for Consumer<T> {
|
||||
}
|
||||
|
||||
impl<T: Config> BlockNumberProvider for Pallet<T> {
|
||||
type BlockNumber = <T as Config>::BlockNumber;
|
||||
type BlockNumber = BlockNumberFor<T>;
|
||||
|
||||
fn current_block_number() -> Self::BlockNumber {
|
||||
Pallet::<T>::block_number()
|
||||
@@ -1813,6 +1793,10 @@ pub mod pallet_prelude {
|
||||
/// Type alias for the `Origin` associated type of system config.
|
||||
pub type OriginFor<T> = <T as crate::Config>::RuntimeOrigin;
|
||||
|
||||
/// Type alias for the `Header`.
|
||||
pub type HeaderFor<T> =
|
||||
<<T as crate::Config>::Block as sp_runtime::traits::HeaderProvider>::HeaderT;
|
||||
|
||||
/// Type alias for the `BlockNumber` associated type of system config.
|
||||
pub type BlockNumberFor<T> = <T as crate::Config>::BlockNumber;
|
||||
pub type BlockNumberFor<T> = <HeaderFor<T> as sp_runtime::traits::Header>::Number;
|
||||
}
|
||||
|
||||
@@ -22,19 +22,14 @@ use frame_support::{
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
BuildStorage, Perbill,
|
||||
};
|
||||
|
||||
type UncheckedExtrinsic = mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = mocking::MockBlock<Test>;
|
||||
|
||||
frame_support::construct_runtime!(
|
||||
pub enum Test where
|
||||
Block = Block,
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
pub enum Test
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
|
||||
}
|
||||
@@ -97,12 +92,11 @@ impl Config for Test {
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Block = Block;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type BlockHashCount = ConstU64<10>;
|
||||
type DbWeight = DbWeight;
|
||||
|
||||
@@ -29,6 +29,19 @@ pub type MockUncheckedExtrinsic<T, Signature = (), Extra = ()> = generic::Unchec
|
||||
|
||||
/// An implementation of `sp_runtime::traits::Block` to be used in tests.
|
||||
pub type MockBlock<T> = generic::Block<
|
||||
generic::Header<<T as crate::Config>::BlockNumber, sp_runtime::traits::BlakeTwo256>,
|
||||
generic::Header<u64, sp_runtime::traits::BlakeTwo256>,
|
||||
MockUncheckedExtrinsic<T>,
|
||||
>;
|
||||
|
||||
/// An implementation of `sp_runtime::traits::Block` to be used in tests with u32 BlockNumber type.
|
||||
pub type MockBlockU32<T> = generic::Block<
|
||||
generic::Header<u32, sp_runtime::traits::BlakeTwo256>,
|
||||
MockUncheckedExtrinsic<T>,
|
||||
>;
|
||||
|
||||
/// An implementation of `sp_runtime::traits::Block` to be used in tests with u128 BlockNumber
|
||||
/// type.
|
||||
pub type MockBlockU128<T> = generic::Block<
|
||||
generic::Header<u128, sp_runtime::traits::BlakeTwo256>,
|
||||
MockUncheckedExtrinsic<T>,
|
||||
>;
|
||||
|
||||
Reference in New Issue
Block a user