mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-24 12:31:17 +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:
@@ -57,6 +57,7 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use frame_support::{log, weights::Weight};
|
||||
use frame_system::pallet_prelude::{BlockNumberFor, HeaderFor};
|
||||
use sp_mmr_primitives::utils;
|
||||
use sp_runtime::{
|
||||
traits::{self, One, Saturating},
|
||||
@@ -91,7 +92,7 @@ pub struct ParentNumberAndHash<T: frame_system::Config> {
|
||||
}
|
||||
|
||||
impl<T: frame_system::Config> LeafDataProvider for ParentNumberAndHash<T> {
|
||||
type LeafData = (<T as frame_system::Config>::BlockNumber, <T as frame_system::Config>::Hash);
|
||||
type LeafData = (BlockNumberFor<T>, <T as frame_system::Config>::Hash);
|
||||
|
||||
fn leaf_data() -> Self::LeafData {
|
||||
(
|
||||
@@ -120,7 +121,6 @@ pub(crate) type HashOf<T, I> = <<T as Config<I>>::Hashing as traits::Hash>::Outp
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
|
||||
@@ -201,7 +201,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
|
||||
fn on_initialize(_n: T::BlockNumber) -> Weight {
|
||||
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
|
||||
use primitives::LeafDataProvider;
|
||||
let leaves = Self::mmr_leaves();
|
||||
let peaks_before = sp_mmr_primitives::utils::NodesUtils::new(leaves).number_of_peaks();
|
||||
@@ -266,11 +266,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
pos: NodeIndex,
|
||||
parent_hash: <T as frame_system::Config>::Hash,
|
||||
) -> sp_std::prelude::Vec<u8> {
|
||||
NodesUtils::node_temp_offchain_key::<<T as frame_system::Config>::Header>(
|
||||
&T::INDEXING_PREFIX,
|
||||
pos,
|
||||
parent_hash,
|
||||
)
|
||||
NodesUtils::node_temp_offchain_key::<HeaderFor<T>>(&T::INDEXING_PREFIX, pos, parent_hash)
|
||||
}
|
||||
|
||||
/// Build canonical offchain key for node `pos` in MMR.
|
||||
@@ -286,7 +282,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
fn leaf_index_to_parent_block_num(
|
||||
leaf_index: LeafIndex,
|
||||
leaves_count: LeafIndex,
|
||||
) -> <T as frame_system::Config>::BlockNumber {
|
||||
) -> BlockNumberFor<T> {
|
||||
// leaves are zero-indexed and were added one per block since pallet activation,
|
||||
// while block numbers are one-indexed, so block number that added `leaf_idx` is:
|
||||
// `block_num = block_num_when_pallet_activated + leaf_idx + 1`
|
||||
@@ -298,16 +294,16 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
}
|
||||
|
||||
/// Convert a block number into a leaf index.
|
||||
fn block_num_to_leaf_index(block_num: T::BlockNumber) -> Result<LeafIndex, Error>
|
||||
fn block_num_to_leaf_index(block_num: BlockNumberFor<T>) -> Result<LeafIndex, Error>
|
||||
where
|
||||
T: frame_system::Config,
|
||||
{
|
||||
let first_mmr_block = utils::first_mmr_block_num::<T::Header>(
|
||||
let first_mmr_block = utils::first_mmr_block_num::<HeaderFor<T>>(
|
||||
<frame_system::Pallet<T>>::block_number(),
|
||||
Self::mmr_leaves(),
|
||||
)?;
|
||||
|
||||
utils::block_num_to_leaf_index::<T::Header>(block_num, first_mmr_block)
|
||||
utils::block_num_to_leaf_index::<HeaderFor<T>>(block_num, first_mmr_block)
|
||||
}
|
||||
|
||||
/// Generate an MMR proof for the given `block_numbers`.
|
||||
@@ -320,8 +316,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
/// all the leaves to be present.
|
||||
/// It may return an error or panic if used incorrectly.
|
||||
pub fn generate_proof(
|
||||
block_numbers: Vec<T::BlockNumber>,
|
||||
best_known_block_number: Option<T::BlockNumber>,
|
||||
block_numbers: Vec<BlockNumberFor<T>>,
|
||||
best_known_block_number: Option<BlockNumberFor<T>>,
|
||||
) -> Result<(Vec<LeafOf<T, I>>, primitives::Proof<HashOf<T, I>>), primitives::Error> {
|
||||
// check whether best_known_block_number provided, else use current best block
|
||||
let best_known_block_number =
|
||||
|
||||
@@ -25,19 +25,12 @@ use frame_support::{
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_mmr_primitives::{Compact, LeafDataProvider};
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup, Keccak256},
|
||||
};
|
||||
use sp_runtime::traits::{BlakeTwo256, IdentityLookup, Keccak256};
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::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>},
|
||||
MMR: pallet_mmr::{Pallet, Storage},
|
||||
@@ -49,12 +42,11 @@ impl frame_system::Config for Test {
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = sp_core::sr25519::Public;
|
||||
type Lookup = IdentityLookup<Self::AccountId>;
|
||||
type Header = Header;
|
||||
type Block = Block;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type BlockHashCount = ConstU64<250>;
|
||||
type DbWeight = ();
|
||||
|
||||
@@ -54,7 +54,7 @@ pub(crate) fn hex(s: &str) -> H256 {
|
||||
s.parse().unwrap()
|
||||
}
|
||||
|
||||
type BlockNumber = <Test as frame_system::Config>::BlockNumber;
|
||||
type BlockNumber = frame_system::pallet_prelude::BlockNumberFor<Test>;
|
||||
|
||||
fn decode_node(
|
||||
v: Vec<u8>,
|
||||
|
||||
Reference in New Issue
Block a user