Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Moves Block to frame_system instead of construct_runtime and removes Header and BlockNumber #2790

Merged
merged 33 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e8039f9
Fixes
gupnik Jun 27, 2023
7feb684
Removes unused import
gupnik Jun 28, 2023
8d79fc4
Uses Block and removes BlockNumber/Header from Chain
gupnik Jun 28, 2023
9d0ae3c
Fixes bridges
gupnik Jun 28, 2023
7c3078a
Fixes
gupnik Jun 28, 2023
49d5cdf
Removes unused import
gupnik Jun 28, 2023
acc6d51
Fixes build
gupnik Jun 28, 2023
acde948
Uses correct RelayBlock
gupnik Jun 28, 2023
2a281d6
Minor fix
gupnik Jun 28, 2023
1a27d2f
Fixes glutton-kusama
gupnik Jun 28, 2023
e36976f
Uses correct RelayBlock
gupnik Jun 28, 2023
0b817d5
Minor fix
gupnik Jun 28, 2023
6269914
Merge branch 'master' of github.com:paritytech/cumulus into gupnik/cr…
gupnik Jun 28, 2023
a05bbba
Fixes benchmark for pallet-bridge-parachains
gupnik Jun 29, 2023
1f89fa7
Adds appropriate constraints
gupnik Jun 29, 2023
d15fff0
Minor fixes
gupnik Jun 29, 2023
895c8fe
Removes unused import
gupnik Jun 29, 2023
0173ae2
Fixes integrity tests
gupnik Jun 29, 2023
5fcfab5
Minor fixes
gupnik Jun 29, 2023
bae8a0c
Updates trait bounds
gupnik Jul 11, 2023
9596411
Merge branch 'master' of github.com:paritytech/cumulus into gupnik/cr…
gupnik Jul 11, 2023
838e528
Uses custom bound for AsPrimitive
gupnik Jul 11, 2023
0b0f42f
Fixes trait bounds
gupnik Jul 11, 2023
c933bc2
Revert "Fixes trait bounds"
gupnik Jul 11, 2023
6c38e45
Revert "Uses custom bound for AsPrimitive"
gupnik Jul 11, 2023
c1b16ff
No AsPrimitive trait bound for now
gupnik Jul 11, 2023
f1facb6
Removes bounds on Number
gupnik Jul 12, 2023
8862191
Merge branch 'master' of github.com:paritytech/cumulus into gupnik/cr…
gupnik Jul 12, 2023
5d89f5f
Merge branch 'master' of github.com:paritytech/cumulus into gupnik/cr…
gupnik Jul 13, 2023
033de71
update lockfile for {"substrate", "polkadot"}
Jul 13, 2023
68ff02a
Formatting
gupnik Jul 13, 2023
d61bac6
".git/.scripts/commands/fmt/fmt.sh"
Jul 13, 2023
58f509a
Minor fix
gupnik Jul 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions bridges/bin/runtime-common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ pub type ThisChainCallOrigin = RuntimeOrigin;
pub type ThisChainHeader = sp_runtime::generic::Header<ThisChainBlockNumber, ThisChainHasher>;
/// Block of `ThisChain`.
pub type ThisChainBlock = frame_system::mocking::MockBlock<TestRuntime>;
/// Unchecked extrinsic of `ThisChain`.
pub type ThisChainUncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRuntime>;

/// Account identifier at the `BridgedChain`.
pub type BridgedChainAccountId = u128;
Expand Down Expand Up @@ -108,10 +106,7 @@ pub const BRIDGED_CHAIN_MAX_EXTRINSIC_WEIGHT: usize = 2048;
pub const BRIDGED_CHAIN_MAX_EXTRINSIC_SIZE: u32 = 1024;

frame_support::construct_runtime! {
pub enum TestRuntime where
Block = ThisChainBlock,
NodeBlock = ThisChainBlock,
UncheckedExtrinsic = ThisChainUncheckedExtrinsic,
pub enum TestRuntime
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Utility: pallet_utility,
Expand Down Expand Up @@ -155,7 +150,7 @@ impl frame_system::Config for TestRuntime {
type Hashing = ThisChainHasher;
type AccountId = ThisChainAccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = ThisChainHeader;
type Block = ThisChainBlock;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU32<250>;
type Version = ();
Expand Down
9 changes: 2 additions & 7 deletions bridges/modules/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,13 @@ pub type TestHeader = crate::BridgedHeader<TestRuntime, ()>;
pub type TestNumber = crate::BridgedBlockNumber<TestRuntime, ()>;

type Block = frame_system::mocking::MockBlock<TestRuntime>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRuntime>;

pub const MAX_BRIDGED_AUTHORITIES: u32 = 5;

use crate as grandpa;

construct_runtime! {
pub enum TestRuntime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum TestRuntime
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Grandpa: grandpa::{Pallet, Call, Event<T>},
Expand All @@ -63,12 +59,11 @@ impl frame_system::Config for TestRuntime {
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type RuntimeCall = RuntimeCall;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
Expand Down
2 changes: 1 addition & 1 deletion bridges/modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub mod pallet {
where
u32: TryFrom<<T as frame_system::Config>::BlockNumber>,
{
fn on_idle(_block: T::BlockNumber, remaining_weight: Weight) -> Weight {
fn on_idle(_block: BlockNumberFor<T>, remaining_weight: Weight) -> Weight {
// we'll need at least to read outbound lane state, kill a message and update lane state
let db_weight = T::DbWeight::get();
if !remaining_weight.all_gte(db_weight.reads_writes(1, 2)) {
Expand Down
9 changes: 2 additions & 7 deletions bridges/modules/messages/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,11 @@ pub type TestRelayer = u64;
pub type TestDispatchLevelResult = ();

type Block = frame_system::mocking::MockBlock<TestRuntime>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRuntime>;

use crate as pallet_bridge_messages;

frame_support::construct_runtime! {
pub enum TestRuntime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum TestRuntime
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Event<T>},
Expand All @@ -100,12 +96,11 @@ impl frame_system::Config for TestRuntime {
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type RuntimeCall = RuntimeCall;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = SubstrateHeader;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
Expand Down
8 changes: 2 additions & 6 deletions bridges/modules/parachains/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub type RelayBlockHeader =
sp_runtime::generic::Header<crate::RelayBlockNumber, crate::RelayBlockHasher>;

type Block = frame_system::mocking::MockBlock<TestRuntime>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRuntime>;

pub const PARAS_PALLET_NAME: &str = "Paras";
pub const UNTRACKED_PARACHAIN_ID: u32 = 10;
Expand Down Expand Up @@ -144,10 +143,7 @@ impl Parachain for BigParachain {
}

construct_runtime! {
pub enum TestRuntime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum TestRuntime
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Grandpa1: pallet_bridge_grandpa::<Instance1>::{Pallet, Event<T>},
Expand All @@ -172,7 +168,7 @@ impl frame_system::Config for TestRuntime {
type Hashing = RegularParachainHasher;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
Expand Down
16 changes: 8 additions & 8 deletions bridges/modules/relayers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub mod pallet {
/// Pay rewards scheme.
type PaymentProcedure: PaymentProcedure<Self::AccountId, Self::Reward>;
/// Stake and slash scheme.
type StakeAndSlash: StakeAndSlash<Self::AccountId, Self::BlockNumber, Self::Reward>;
type StakeAndSlash: StakeAndSlash<Self::AccountId, BlockNumberFor<Self>, Self::Reward>;
/// Pallet call weights.
type WeightInfo: WeightInfoExt;
}
Expand Down Expand Up @@ -117,7 +117,7 @@ pub mod pallet {
/// Registration allows relayer to get priority boost for its message delivery transactions.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::register())]
pub fn register(origin: OriginFor<T>, valid_till: T::BlockNumber) -> DispatchResult {
pub fn register(origin: OriginFor<T>, valid_till: BlockNumberFor<T>) -> DispatchResult {
let relayer = ensure_signed(origin)?;

// valid till must be larger than the current block number and the lease must be larger
Expand Down Expand Up @@ -330,10 +330,10 @@ pub mod pallet {
}

/// Return required registration lease.
pub(crate) fn required_registration_lease() -> T::BlockNumber {
pub(crate) fn required_registration_lease() -> BlockNumberFor<T> {
<T::StakeAndSlash as StakeAndSlash<
T::AccountId,
T::BlockNumber,
BlockNumberFor<T>,
T::Reward,
>>::RequiredRegistrationLease::get()
}
Expand All @@ -342,7 +342,7 @@ pub mod pallet {
pub(crate) fn required_stake() -> T::Reward {
<T::StakeAndSlash as StakeAndSlash<
T::AccountId,
T::BlockNumber,
BlockNumberFor<T>,
T::Reward,
>>::RequiredStake::get()
}
Expand Down Expand Up @@ -383,7 +383,7 @@ pub mod pallet {
/// Relayer account that has been registered.
relayer: T::AccountId,
/// Relayer registration.
registration: Registration<T::BlockNumber, T::Reward>,
registration: Registration<BlockNumberFor<T>, T::Reward>,
},
/// Relayer has been `deregistered`.
Deregistered {
Expand All @@ -395,7 +395,7 @@ pub mod pallet {
/// Relayer account that has been `deregistered`.
relayer: T::AccountId,
/// Registration that was removed.
registration: Registration<T::BlockNumber, T::Reward>,
registration: Registration<BlockNumberFor<T>, T::Reward>,
},
}

Expand Down Expand Up @@ -445,7 +445,7 @@ pub mod pallet {
_,
Blake2_128Concat,
T::AccountId,
Registration<T::BlockNumber, T::Reward>,
Registration<BlockNumberFor<T>, T::Reward>,
OptionQuery,
>;
}
Expand Down
9 changes: 2 additions & 7 deletions bridges/modules/relayers/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ pub type TestStakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
>;

type Block = frame_system::mocking::MockBlock<TestRuntime>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRuntime>;

frame_support::construct_runtime! {
pub enum TestRuntime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum TestRuntime
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Event<T>},
Expand All @@ -69,12 +65,11 @@ impl frame_system::Config for TestRuntime {
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type RuntimeCall = RuntimeCall;
type BlockNumber = BlockNumber;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = SubstrateHeader;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = frame_support::traits::ConstU64<250>;
type Version = ();
Expand Down
3 changes: 1 addition & 2 deletions bridges/primitives/chain-bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ use sp_std::prelude::*;
pub struct BridgeHubKusama;

impl Chain for BridgeHubKusama {
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hasher = Hasher;
type Header = Header;
type Block = Block;

type AccountId = AccountId;
type Balance = Balance;
Expand Down
3 changes: 1 addition & 2 deletions bridges/primitives/chain-bridge-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ use sp_std::prelude::*;
pub struct BridgeHubPolkadot;

impl Chain for BridgeHubPolkadot {
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hasher = Hasher;
type Header = Header;
type Block = Block;

type AccountId = AccountId;
type Balance = Balance;
Expand Down
3 changes: 1 addition & 2 deletions bridges/primitives/chain-bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ use sp_std::prelude::*;
pub struct BridgeHubRococo;

impl Chain for BridgeHubRococo {
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hasher = Hasher;
type Header = Header;
type Block = Block;

type AccountId = AccountId;
type Balance = Balance;
Expand Down
3 changes: 1 addition & 2 deletions bridges/primitives/chain-bridge-hub-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ use sp_std::prelude::*;
pub struct BridgeHubWococo;

impl Chain for BridgeHubWococo {
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hasher = Hasher;
type Header = Header;
type Block = Block;

type AccountId = AccountId;
type Balance = Balance;
Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/header-chain/src/justification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<H: HeaderT> GrandpaJustification<H> {
/// any precise calculations - that's just an estimation.
pub fn max_reasonable_size<C>(required_precommits: u32) -> u32
where
C: Chain<Header = H> + ChainWithGrandpa,
C: Chain + ChainWithGrandpa,
{
// we don't need precise results here - just estimations, so some details
// are removed from computations (e.g. bytes required to encode vector length)
Expand Down
4 changes: 2 additions & 2 deletions bridges/primitives/header-chain/tests/implementation_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ pub fn make_default_justification(header: &TestHeader) -> GrandpaJustification<T
// the `finality_grandpa::validate_commit` function has two ways to report an unsuccessful
// commit validation:
//
// 1) to return `Err()` (which only may happen if `finality_grandpa::Chain` implementation
// returns an error);
// 1) to return `Err()` (which only may happen if `finality_grandpa::Chain` implementation returns
// an error);
// 2) to return `Ok(validation_result)` if `validation_result.is_valid()` is false.
//
// Our implementation would just return error in both cases.
Expand Down
3 changes: 1 addition & 2 deletions bridges/primitives/polkadot-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,9 @@ pub type Address = MultiAddress<AccountId, ()>;
pub struct PolkadotLike;

impl Chain for PolkadotLike {
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hasher = Hasher;
type Header = Header;
type Block = Block;

type AccountId = AccountId;
type Balance = Balance;
Expand Down
42 changes: 9 additions & 33 deletions bridges/primitives/runtime/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use frame_support::{weights::Weight, Parameter};
use num_traits::{AsPrimitive, Bounded, CheckedSub, Saturating, SaturatingAdd, Zero};
use sp_runtime::{
traits::{
AtLeast32Bit, AtLeast32BitUnsigned, Hash as HashT, Header as HeaderT, MaybeDisplay,
MaybeSerialize, MaybeSerializeDeserialize, Member, SimpleBitOps, Verify,
AtLeast32Bit, AtLeast32BitUnsigned, Block as BlockT, Hash as HashT, Header as HeaderT,
HeaderProvider, MaybeDisplay, MaybeSerialize, MaybeSerializeDeserialize, Member,
SimpleBitOps, Verify,
},
FixedPointOperand,
};
Expand Down Expand Up @@ -91,27 +92,6 @@ impl<ChainCall: Encode> Encode for EncodedOrDecodedCall<ChainCall> {

/// Minimal Substrate-based chain representation that may be used from no_std environment.
pub trait Chain: Send + Sync + 'static {
/// A type that fulfills the abstract idea of what a Substrate block number is.
// Constraits come from the associated Number type of `sp_runtime::traits::Header`
// See here for more info:
// https://crates.parity.io/sp_runtime/traits/trait.Header.html#associatedtype.Number
//
// Note that the `AsPrimitive<usize>` trait is required by the GRANDPA justification
// verifier, and is not usually part of a Substrate Header's Number type.
type BlockNumber: Parameter
+ Member
+ MaybeSerializeDeserialize
+ Hash
+ Copy
+ Default
+ MaybeDisplay
+ AtLeast32BitUnsigned
+ FromStr
+ AsPrimitive<usize>
+ Default
+ Saturating
+ MaxEncodedLen;

/// A type that fulfills the abstract idea of what a Substrate hash is.
// Constraits come from the associated Hash type of `sp_runtime::traits::Header`
// See here for more info:
Expand All @@ -136,13 +116,10 @@ pub trait Chain: Send + Sync + 'static {
// https://crates.parity.io/sp_runtime/traits/trait.Header.html#associatedtype.Hashing
type Hasher: HashT<Output = Self::Hash>;

/// A type that fulfills the abstract idea of what a Substrate header is.
/// A type that fulfills the abstract idea of what a Substrate block is.
// See here for more info:
// https://crates.parity.io/sp_runtime/traits/trait.Header.html
type Header: Parameter
+ HeaderT<Number = Self::BlockNumber, Hash = Self::Hash>
+ HeaderIdProvider<Self::Header>
+ MaybeSerializeDeserialize;
// https://crates.parity.io/sp_runtime/traits/trait.Block.html
type Block: Parameter + BlockT<Hash = Self::Hash> + MaybeSerializeDeserialize;

/// The user account identifier type for the runtime.
type AccountId: Parameter
Expand Down Expand Up @@ -200,10 +177,9 @@ impl<T> Chain for T
where
T: Send + Sync + 'static + UnderlyingChainProvider,
{
type BlockNumber = <T::Chain as Chain>::BlockNumber;
type Hash = <T::Chain as Chain>::Hash;
type Hasher = <T::Chain as Chain>::Hasher;
type Header = <T::Chain as Chain>::Header;
type Block = <T::Chain as Chain>::Block;
type AccountId = <T::Chain as Chain>::AccountId;
type Balance = <T::Chain as Chain>::Balance;
type Index = <T::Chain as Chain>::Index;
Expand Down Expand Up @@ -244,7 +220,7 @@ impl<Para: Parachain> frame_support::traits::Get<u32> for ParachainIdOf<Para> {
pub type UnderlyingChainOf<C> = <C as UnderlyingChainProvider>::Chain;

/// Block number used by the chain.
pub type BlockNumberOf<C> = <C as Chain>::BlockNumber;
pub type BlockNumberOf<C> = <<<C as Chain>::Block as HeaderProvider>::HeaderT as HeaderT>::Number;

/// Hash type used by the chain.
pub type HashOf<C> = <C as Chain>::Hash;
Expand All @@ -253,7 +229,7 @@ pub type HashOf<C> = <C as Chain>::Hash;
pub type HasherOf<C> = <C as Chain>::Hasher;

/// Header type used by the chain.
pub type HeaderOf<C> = <C as Chain>::Header;
pub type HeaderOf<C> = <<C as Chain>::Block as HeaderProvider>::HeaderT;

/// Account id type used by the chain.
pub type AccountIdOf<C> = <C as Chain>::AccountId;
Expand Down
Loading