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

[Backport] Missing PR's to fix compilation issues in the source branch #2963

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
665 changes: 349 additions & 316 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ members = [
"pallets/xcmp-queue",
"parachain-template/node",
"parachain-template/runtime",
"primitives/aura",
"primitives/core",
"primitives/parachain-inherent",
"primitives/timestamp",
Expand Down Expand Up @@ -74,3 +75,4 @@ opt-level = 3
inherits = "release"
lto = true
codegen-units = 1

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ cargo build --release --bin polkadot-parachain
./target/release/polkadot-parachain export-genesis-wasm > genesis-wasm

# Collator1
./target/release/polkadot-parachain --collator --alice --force-authoring --tmp --port 40335 --ws-port 9946 -- --execution wasm --chain ../polkadot/rococo-local-cfde.json --port 30335
./target/release/polkadot-parachain --collator --alice --force-authoring --tmp --port 40335 --rpc-port 9946 -- --chain ../polkadot/rococo-local-cfde.json --port 30335

# Collator2
./target/release/polkadot-parachain --collator --bob --force-authoring --tmp --port 40336 --ws-port 9947 -- --execution wasm --chain ../polkadot/rococo-local-cfde.json --port 30336
./target/release/polkadot-parachain --collator --bob --force-authoring --tmp --port 40336 --rpc-port 9947 -- --chain ../polkadot/rococo-local-cfde.json --port 30336

# Parachain Full Node 1
./target/release/polkadot-parachain --tmp --port 40337 --ws-port 9948 -- --execution wasm --chain ../polkadot/rococo-local-cfde.json --port 30337
./target/release/polkadot-parachain --tmp --port 40337 --rpc-port 9948 -- --chain ../polkadot/rococo-local-cfde.json --port 30337
```

#### Register the parachain
Expand Down Expand Up @@ -267,5 +267,5 @@ docker build --tag $OWNER/$IMAGE_NAME --file ./docker/polkadot-parachain_builder
You may then run your new container:

```bash
docker run --rm -it $OWNER/$IMAGE_NAME --collator --tmp --execution wasm --chain /specs/westmint.json
docker run --rm -it $OWNER/$IMAGE_NAME --collator --tmp --chain /specs/westmint.json
```
10 changes: 5 additions & 5 deletions bridges/bin/runtime-common/src/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ use pallet_bridge_messages::WeightInfoExt as _;
use sp_runtime::traits::SignedExtension;

/// Macro that ensures that the runtime configuration and chain primitives crate are sharing
/// the same types (index, block number, hash, hasher, account id and header).
/// the same types (nonce, block number, hash, hasher, account id and header).
#[macro_export]
macro_rules! assert_chain_types(
( runtime: $r:path, this_chain: $this:path ) => {
{
// if one of asserts fail, then either bridge isn't configured properly (or alternatively - non-standard
// configuration is used), or something has broke existing configuration (meaning that all bridged chains
// and relays will stop functioning)
use frame_system::Config as SystemConfig;
use frame_system::{Config as SystemConfig, pallet_prelude::{BlockNumberFor, HeaderFor}};
use static_assertions::assert_type_eq_all;

assert_type_eq_all!(<$r as SystemConfig>::Index, bp_runtime::IndexOf<$this>);
assert_type_eq_all!(<$r as SystemConfig>::BlockNumber, bp_runtime::BlockNumberOf<$this>);
assert_type_eq_all!(<$r as SystemConfig>::Nonce, bp_runtime::NonceOf<$this>);
assert_type_eq_all!(BlockNumberFor<$r>, bp_runtime::BlockNumberOf<$this>);
assert_type_eq_all!(<$r as SystemConfig>::Hash, bp_runtime::HashOf<$this>);
assert_type_eq_all!(<$r as SystemConfig>::Hashing, bp_runtime::HasherOf<$this>);
assert_type_eq_all!(<$r as SystemConfig>::AccountId, bp_runtime::AccountIdOf<$this>);
assert_type_eq_all!(<$r as SystemConfig>::Header, bp_runtime::HeaderOf<$this>);
assert_type_eq_all!(HeaderFor<$r>, bp_runtime::HeaderOf<$this>);
}
}
);
Expand Down
22 changes: 8 additions & 14 deletions bridges/bin/runtime-common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ pub type ThisChainCallOrigin = RuntimeOrigin;
/// Header of `ThisChain`.
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>;
pub type ThisChainBlock = frame_system::mocking::MockBlockU32<TestRuntime>;

/// Account identifier at the `BridgedChain`.
pub type BridgedChainAccountId = u128;
Expand Down Expand Up @@ -108,12 +106,9 @@ 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>},
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Utility: pallet_utility,
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
Expand Down Expand Up @@ -148,14 +143,13 @@ parameter_types! {

impl frame_system::Config for TestRuntime {
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type Nonce = u64;
type RuntimeCall = RuntimeCall;
type BlockNumber = ThisChainBlockNumber;
type Hash = ThisChainHash;
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 Expand Up @@ -324,7 +318,7 @@ impl Chain for ThisUnderlyingChain {
type Header = ThisChainHeader;
type AccountId = ThisChainAccountId;
type Balance = ThisChainBalance;
type Index = u32;
type Nonce = u32;
type Signature = sp_runtime::MultiSignature;

fn max_extrinsic_size() -> u32 {
Expand Down Expand Up @@ -364,7 +358,7 @@ impl Chain for BridgedUnderlyingChain {
type Header = BridgedChainHeader;
type AccountId = BridgedChainAccountId;
type Balance = BridgedChainBalance;
type Index = u32;
type Nonce = u32;
type Signature = sp_runtime::MultiSignature;

fn max_extrinsic_size() -> u32 {
Expand All @@ -390,7 +384,7 @@ impl Chain for BridgedUnderlyingParachain {
type Header = BridgedChainHeader;
type AccountId = BridgedChainAccountId;
type Balance = BridgedChainBalance;
type Index = u32;
type Nonce = u32;
type Signature = sp_runtime::MultiSignature;

fn max_extrinsic_size() -> u32 {
Expand Down
4 changes: 3 additions & 1 deletion bridges/modules/grandpa/src/call_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ pub(crate) fn submit_finality_proof_info_from_args<T: Config<I>, I: 'static>(
/// Returns maximal expected size of `submit_finality_proof` call arguments.
fn max_expected_call_size<T: Config<I>, I: 'static>(required_precommits: u32) -> u32 {
let max_expected_justification_size =
GrandpaJustification::max_reasonable_size::<T::BridgedChain>(required_precommits);
GrandpaJustification::<BridgedHeader<T, I>>::max_reasonable_size::<T::BridgedChain>(
required_precommits,
);

// call arguments are header and justification
T::BridgedChain::MAX_HEADER_SIZE.saturating_add(max_expected_justification_size)
Expand Down
54 changes: 12 additions & 42 deletions bridges/modules/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@
pub use storage_types::StoredAuthoritySet;

use bp_header_chain::{
justification::GrandpaJustification, ChainWithGrandpa, HeaderChain, InitializationData,
StoredHeaderData, StoredHeaderDataBuilder,
justification::GrandpaJustification, ChainWithGrandpa, GrandpaConsensusLogReader, HeaderChain,
InitializationData, StoredHeaderData, StoredHeaderDataBuilder,
};
use bp_runtime::{BlockNumberOf, HashOf, HasherOf, HeaderId, HeaderOf, OwnedBridgeModule};
use finality_grandpa::voter_set::VoterSet;
use frame_support::{dispatch::PostDispatchInfo, ensure, DefaultNoBound};
use sp_consensus_grandpa::{ConsensusLog, GRANDPA_ENGINE_ID};
use sp_runtime::{
traits::{Header as HeaderT, Zero},
SaturatedConversion,
Expand Down Expand Up @@ -380,7 +379,7 @@ pub mod pallet {
}

#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
impl<T: Config<I>, I: 'static> BuildGenesisConfig for GenesisConfig<T, I> {
fn build(&self) {
if let Some(ref owner) = self.owner {
<PalletOwner<T, I>>::put(owner);
Expand Down Expand Up @@ -443,11 +442,17 @@ pub mod pallet {

// We don't support forced changes - at that point governance intervention is required.
ensure!(
super::find_forced_change(header).is_none(),
GrandpaConsensusLogReader::<BridgedBlockNumber<T, I>>::find_forced_change(
header.digest()
)
.is_none(),
<Error<T, I>>::UnsupportedScheduledChange
);

if let Some(change) = super::find_scheduled_change(header) {
if let Some(change) =
GrandpaConsensusLogReader::<BridgedBlockNumber<T, I>>::find_scheduled_change(
header.digest(),
) {
// GRANDPA only includes a `delay` for forced changes, so this isn't valid.
ensure!(change.delay == Zero::zero(), <Error<T, I>>::UnsupportedScheduledChange);

Expand Down Expand Up @@ -616,42 +621,6 @@ impl<T: Config<I>, I: 'static> HeaderChain<BridgedChain<T, I>> for GrandpaChainH
}
}

pub(crate) fn find_scheduled_change<H: HeaderT>(
header: &H,
) -> Option<sp_consensus_grandpa::ScheduledChange<H::Number>> {
use sp_runtime::generic::OpaqueDigestItemId;

let id = OpaqueDigestItemId::Consensus(&GRANDPA_ENGINE_ID);

let filter_log = |log: ConsensusLog<H::Number>| match log {
ConsensusLog::ScheduledChange(change) => Some(change),
_ => None,
};

// find the first consensus digest with the right ID which converts to
// the right kind of consensus log.
header.digest().convert_first(|l| l.try_to(id).and_then(filter_log))
}

/// Checks the given header for a consensus digest signaling a **forced** scheduled change and
/// extracts it.
pub(crate) fn find_forced_change<H: HeaderT>(
header: &H,
) -> Option<(H::Number, sp_consensus_grandpa::ScheduledChange<H::Number>)> {
use sp_runtime::generic::OpaqueDigestItemId;

let id = OpaqueDigestItemId::Consensus(&GRANDPA_ENGINE_ID);

let filter_log = |log: ConsensusLog<H::Number>| match log {
ConsensusLog::ForcedChange(delay, change) => Some((delay, change)),
_ => None,
};

// find the first consensus digest with the right ID which converts to
// the right kind of consensus log.
header.digest().convert_first(|l| l.try_to(id).and_then(filter_log))
}

/// (Re)initialize bridge with given header for using it in `pallet-bridge-messages` benchmarks.
#[cfg(feature = "runtime-benchmarks")]
pub fn initialize_for_benchmarks<T: Config<I>, I: 'static>(header: BridgedHeader<T, I>) {
Expand Down Expand Up @@ -685,6 +654,7 @@ mod tests {
storage::generator::StorageValue,
};
use frame_system::{EventRecord, Phase};
use sp_consensus_grandpa::{ConsensusLog, GRANDPA_ENGINE_ID};
use sp_core::Get;
use sp_runtime::{Digest, DigestItem, DispatchError};

Expand Down
25 changes: 10 additions & 15 deletions bridges/modules/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,25 @@ use frame_support::{
};
use sp_core::sr25519::Signature;
use sp_runtime::{
testing::{Header, H256},
testing::H256,
traits::{BlakeTwo256, IdentityLookup},
Perbill,
};

pub type AccountId = u64;
pub type TestHeader = crate::BridgedHeader<TestRuntime, ()>;
pub type TestNumber = crate::BridgedBlockNumber<TestRuntime, ()>;
pub type TestHeader = sp_runtime::testing::Header;
pub type TestNumber = u64;

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>},
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Grandpa: grandpa::{Pallet, Call, Event<T>},
}
}
Expand All @@ -61,14 +57,13 @@ parameter_types! {

impl frame_system::Config for TestRuntime {
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type Nonce = 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 Expand Up @@ -105,14 +100,14 @@ impl grandpa::Config for TestRuntime {
pub struct TestBridgedChain;

impl Chain for TestBridgedChain {
type BlockNumber = <TestRuntime as frame_system::Config>::BlockNumber;
type BlockNumber = TestNumber;
type Hash = <TestRuntime as frame_system::Config>::Hash;
type Hasher = <TestRuntime as frame_system::Config>::Hashing;
type Header = <TestRuntime as frame_system::Config>::Header;
type Header = TestHeader;

type AccountId = AccountId;
type Balance = u64;
type Index = u64;
type Nonce = u64;
type Signature = Signature;

fn max_extrinsic_size() -> u32 {
Expand Down
6 changes: 3 additions & 3 deletions bridges/modules/messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I>
where
u32: TryFrom<<T as frame_system::Config>::BlockNumber>,
u32: TryFrom<BlockNumberFor<T>>,
{
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 Expand Up @@ -597,7 +597,7 @@ pub mod pallet {
}

#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
impl<T: Config<I>, I: 'static> BuildGenesisConfig for GenesisConfig<T, I> {
fn build(&self) {
PalletOperatingMode::<T, I>::put(self.operating_mode);
if let Some(ref owner) = self.owner {
Expand Down
18 changes: 6 additions & 12 deletions bridges/modules/messages/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ use frame_support::{
use scale_info::TypeInfo;
use sp_core::H256;
use sp_runtime::{
testing::Header as SubstrateHeader,
traits::{BlakeTwo256, ConstU32, IdentityLookup},
Perbill,
BuildStorage, Perbill,
};
use std::{
collections::{BTreeMap, VecDeque},
Expand Down Expand Up @@ -71,17 +70,13 @@ 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>},
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Event<T>},
Messages: pallet_bridge_messages::{Pallet, Call, Event<T>},
}
Expand All @@ -98,14 +93,13 @@ pub type DbWeight = RocksDbWeight;

impl frame_system::Config for TestRuntime {
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type Nonce = 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 Expand Up @@ -487,7 +481,7 @@ pub fn inbound_unrewarded_relayers_state(lane: bp_messages::LaneId) -> Unrewarde

/// Return test externalities to use in tests.
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<TestRuntime>().unwrap();
let mut t = frame_system::GenesisConfig::<TestRuntime>::default().build_storage().unwrap();
pallet_balances::GenesisConfig::<TestRuntime> { balances: vec![(ENDOWED_ACCOUNT, 1_000_000)] }
.assimilate_storage(&mut t)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion bridges/modules/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ pub mod pallet {
}

#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
impl<T: Config<I>, I: 'static> BuildGenesisConfig for GenesisConfig<T, I> {
fn build(&self) {
PalletOperatingMode::<T, I>::put(self.operating_mode);
if let Some(ref owner) = self.owner {
Expand Down
Loading