Skip to content

Commit

Permalink
BHK/P alignments (#2115)
Browse files Browse the repository at this point in the history
* Constants

* Unused import?

* Cargo.lock

* Unused deps

* TODO: fix doc or reimport?

* Try to aviod redefine para_id constant for `RefundableParachainId`

* Checked and removed TODOs
  • Loading branch information
bkontur authored May 11, 2023
1 parent 2a66aa3 commit 696ff1c
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 47 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run

parameter_types! {
pub const RialtoParachainMessagesLane: bp_messages::LaneId = rialto_parachain_messages::XCM_LANE;
pub const RialtoParachainId: u32 = bp_rialto_parachain::RIALTO_PARACHAIN_ID;
pub const RialtoParasPalletName: &'static str = bp_rialto::PARAS_PALLET_NAME;
pub const WestendParasPalletName: &'static str = bp_westend::PARAS_PALLET_NAME;
pub const MaxRialtoParaHeadDataSize: u32 = bp_rialto::MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE;
Expand Down Expand Up @@ -602,7 +601,7 @@ bp_runtime::generate_static_str_provider!(BridgeRefundRialtoPara2000Lane0Msgs);
pub type PriorityBoostPerMessage = ConstU64<324_316_715>;
pub type BridgeRefundRialtoParachainMessages = RefundBridgedParachainMessages<
Runtime,
RefundableParachain<WithRialtoParachainsInstance, RialtoParachainId>,
RefundableParachain<WithRialtoParachainsInstance, bp_rialto_parachain::RialtoParachain>,
RefundableMessagesLane<WithRialtoParachainMessagesInstance, RialtoParachainMessagesLane>,
ActualFeeRefund<Runtime>,
PriorityBoostPerMessage,
Expand Down
2 changes: 1 addition & 1 deletion bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ pub type XcmOriginToTransactDispatchOrigin = (
// using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
// foreign chains who want to have a local sovereign account on this chain which they control.
SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
// Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when
// Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when
// recognised.
RelayChainAsNative<RelayOrigin, RuntimeOrigin>,
// Native converter for sibling Parachains; will convert to a `SiblingPara` origin when
Expand Down
6 changes: 1 addition & 5 deletions bin/runtime-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", d
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }

# Polkadot dependencies
pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "master", default-features = false }

[dev-dependencies]
bp-test-utils = { path = "../../primitives/test-utils" }
Expand All @@ -68,7 +66,6 @@ std = [
"pallet-bridge-relayers/std",
"pallet-transaction-payment/std",
"pallet-utility/std",
"pallet-xcm/std",
"scale-info/std",
"sp-api/std",
"sp-core/std",
Expand All @@ -78,13 +75,12 @@ std = [
"sp-trie/std",
"xcm/std",
"xcm-builder/std",
"xcm-executor/std",
]
runtime-benchmarks = [
"pallet-bridge-grandpa/runtime-benchmarks",
"pallet-bridge-messages/runtime-benchmarks",
"pallet-bridge-parachains/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"pallet-bridge-relayers/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
]
integrity-test = [
Expand Down
19 changes: 15 additions & 4 deletions bin/runtime-common/src/refund_relayer_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::messages_call_ext::{
};
use bp_messages::{LaneId, MessageNonce};
use bp_relayers::{RewardsAccountOwner, RewardsAccountParams};
use bp_runtime::{RangeInclusiveExt, StaticStrProvider};
use bp_runtime::{Parachain, ParachainIdOf, RangeInclusiveExt, StaticStrProvider};
use codec::{Decode, Encode};
use frame_support::{
dispatch::{CallableCallFor, DispatchInfo, Dispatchable, PostDispatchInfo},
Expand Down Expand Up @@ -71,16 +71,27 @@ pub trait RefundableParachainId {
}

/// Default implementation of `RefundableParachainId`.
pub struct RefundableParachain<Instance, Id>(PhantomData<(Instance, Id)>);
pub struct DefaultRefundableParachainId<Instance, Id>(PhantomData<(Instance, Id)>);

impl<Instance, Id> RefundableParachainId for RefundableParachain<Instance, Id>
impl<Instance, Id> RefundableParachainId for DefaultRefundableParachainId<Instance, Id>
where
Id: Get<u32>,
{
type Instance = Instance;
type Id = Id;
}

/// Implementation of `RefundableParachainId` for `trait Parachain`.
pub struct RefundableParachain<Instance, Para>(PhantomData<(Instance, Para)>);

impl<Instance, Para> RefundableParachainId for RefundableParachain<Instance, Para>
where
Para: Parachain,
{
type Instance = Instance;
type Id = ParachainIdOf<Para>;
}

/// Trait identifying a bridged messages lane. A relayer might be refunded for delivering messages
/// coming from this lane.
pub trait RefundableMessagesLaneId {
Expand Down Expand Up @@ -682,7 +693,7 @@ mod tests {
bp_runtime::generate_static_str_provider!(TestExtension);
type TestExtension = RefundBridgedParachainMessages<
TestRuntime,
RefundableParachain<(), TestParachain>,
DefaultRefundableParachainId<(), TestParachain>,
RefundableMessagesLane<(), TestLaneId>,
ActualFeeRefund<TestRuntime>,
ConstU64<1>,
Expand Down
8 changes: 4 additions & 4 deletions modules/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ pub mod pallet {
Some(parachain_head_data) => parachain_head_data,
None => {
log::trace!(
target: LOG_TARGET,
"The head of parachain {:?} has been provided, but it is not tracked by the pallet",
parachain,
);
target: LOG_TARGET,
"The head of parachain {:?} has been provided, but it is not tracked by the pallet",
parachain,
);
Self::deposit_event(Event::UntrackedParachainRejected { parachain });
continue
},
Expand Down
2 changes: 0 additions & 2 deletions primitives/chain-bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,10 @@ pub type Address = MultiAddress<AccountId, ()>;
pub const BRIDGE_HUB_KUSAMA_PARACHAIN_ID: u32 = 1002;

/// Name of the With-BridgeHubKusama messages pallet instance that is deployed at bridged chains.
// TODO: check me (https://github.com/paritytech/parity-bridges-common/issues/1945)
pub const WITH_BRIDGE_HUB_KUSAMA_MESSAGES_PALLET_NAME: &str = "BridgeKusamaMessages";

/// Name of the With-BridgeHubKusama bridge-relayers pallet instance that is deployed at bridged
/// chains.
// TODO: check me (https://github.com/paritytech/parity-bridges-common/issues/1945)
pub const WITH_BRIDGE_HUB_KUSAMA_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";

decl_bridge_finality_runtime_apis!(bridge_hub_kusama);
Expand Down
3 changes: 0 additions & 3 deletions primitives/chain-bridge-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,13 @@ impl Parachain for BridgeHubPolkadot {
}

/// Identifier of BridgeHubPolkadot in the Polkadot relay chain.
// TODO: check me (https://github.com/paritytech/parity-bridges-common/issues/1945)
pub const BRIDGE_HUB_POLKADOT_PARACHAIN_ID: u32 = 1002;

/// Name of the With-BridgeHubPolkadot messages pallet instance that is deployed at bridged chains.
// TODO: check me (https://github.com/paritytech/parity-bridges-common/issues/1945)
pub const WITH_BRIDGE_HUB_POLKADOT_MESSAGES_PALLET_NAME: &str = "BridgePolkadotMessages";

/// Name of the With-BridgeHubPolkadot bridge-relayers pallet instance that is deployed at bridged
/// chains.
// TODO: check me (https://github.com/paritytech/parity-bridges-common/issues/1945)
pub const WITH_BRIDGE_HUB_POLKADOT_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";

decl_bridge_finality_runtime_apis!(bridge_hub_polkadot);
Expand Down
7 changes: 7 additions & 0 deletions primitives/chain-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ pub const PARAS_PALLET_NAME: &str = "Paras";
/// Name of the With-Kusama GRANDPA pallet instance that is deployed at bridged chains.
pub const WITH_KUSAMA_GRANDPA_PALLET_NAME: &str = "BridgeKusamaGrandpa";

/// Maximal size of encoded `bp_parachains::ParaStoredHeaderData` structure among all Polkadot
/// parachains.
///
/// It includes the block number and state root, so it shall be near 40 bytes, but let's have some
/// reserve.
pub const MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE: u32 = 128;

decl_bridge_finality_runtime_apis!(kusama);
7 changes: 7 additions & 0 deletions primitives/chain-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ pub const PARAS_PALLET_NAME: &str = "Paras";
/// Name of the With-Polkadot GRANDPA pallet instance that is deployed at bridged chains.
pub const WITH_POLKADOT_GRANDPA_PALLET_NAME: &str = "BridgePolkadotGrandpa";

/// Maximal size of encoded `bp_parachains::ParaStoredHeaderData` structure among all Polkadot
/// parachains.
///
/// It includes the block number and state root, so it shall be near 40 bytes, but let's have some
/// reserve.
pub const MAX_NESTED_PARACHAIN_HEAD_DATA_SIZE: u32 = 128;

decl_bridge_finality_runtime_apis!(polkadot);
4 changes: 2 additions & 2 deletions primitives/polkadot-core/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
//!
//! Even though this (bridges) repository references polkadot repository, we can't
//! reference polkadot crates from pallets. That's because bridges repository is
//! included in the polkadot repository and included pallets are used by polkadot
//! chains. Having pallets that are referencing polkadot, would mean that there may
//! included in the Cumulus repository and included pallets are used by Cumulus
//! parachains. Having pallets that are referencing polkadot, would mean that there may
//! be two versions of polkadot crates included in the runtime. Which is bad.
use bp_runtime::{RawStorageProof, Size};
Expand Down
8 changes: 8 additions & 0 deletions primitives/runtime/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ where
const PARACHAIN_ID: u32 = <<T as UnderlyingChainProvider>::Chain as Parachain>::PARACHAIN_ID;
}

/// Adapter for `Get<u32>` to access `PARACHAIN_ID` from `trait Parachain`
pub struct ParachainIdOf<Para>(sp_std::marker::PhantomData<Para>);
impl<Para: Parachain> frame_support::traits::Get<u32> for ParachainIdOf<Para> {
fn get() -> u32 {
Para::PARACHAIN_ID
}
}

/// Underlying chain type.
pub type UnderlyingChainOf<C> = <C as UnderlyingChainProvider>::Chain;

Expand Down
6 changes: 3 additions & 3 deletions primitives/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use sp_std::{convert::TryFrom, fmt::Debug, ops::RangeInclusive, vec, vec::Vec};

pub use chain::{
AccountIdOf, AccountPublicOf, BalanceOf, BlockNumberOf, Chain, EncodedOrDecodedCall, HashOf,
HasherOf, HeaderOf, IndexOf, Parachain, SignatureOf, TransactionEraOf, UnderlyingChainOf,
UnderlyingChainProvider,
HasherOf, HeaderOf, IndexOf, Parachain, ParachainIdOf, SignatureOf, TransactionEraOf,
UnderlyingChainOf, UnderlyingChainProvider,
};
pub use frame_support::storage::storage_prefix as storage_value_final_key;
use num_traits::{CheckedAdd, CheckedSub, One, SaturatingAdd, Zero};
Expand Down Expand Up @@ -95,7 +95,7 @@ pub const BRIDGE_HUB_WOCOCO_CHAIN_ID: ChainId = *b"bhwo";
pub const BRIDGE_HUB_KUSAMA_CHAIN_ID: ChainId = *b"bhks";

/// BridgeHubPolkadot chain id.
pub const BRIDGE_HUB_POLKADOT_CHAIN_ID: ChainId = *b"bhwo";
pub const BRIDGE_HUB_POLKADOT_CHAIN_ID: ChainId = *b"bhpd";

/// Generic header Id.
#[derive(
Expand Down
3 changes: 1 addition & 2 deletions relays/bin-substrate/src/chains/kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl CliChain for Kusama {
}

impl CliChain for BridgeHubKusama {
// TODO: fix me (https://github.com/paritytech/parity-bridges-common/issues/1945)
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> =
Some(SimpleRuntimeVersion { spec_version: 4242, transaction_version: 42 });
Some(SimpleRuntimeVersion { spec_version: 9410, transaction_version: 21 });
}
3 changes: 1 addition & 2 deletions relays/bin-substrate/src/chains/polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ impl CliChain for Polkadot {
}

impl CliChain for BridgeHubPolkadot {
// TODO: fix me (https://github.com/paritytech/parity-bridges-common/issues/1945)
const RUNTIME_VERSION: Option<SimpleRuntimeVersion> =
Some(SimpleRuntimeVersion { spec_version: 4242, transaction_version: 42 });
Some(SimpleRuntimeVersion { spec_version: 9410, transaction_version: 22 });
}
9 changes: 3 additions & 6 deletions relays/client-bridge-hub-kusama/src/runtime_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,13 @@ pub enum Call {
Utility(UtilityCall<Call>),

/// Polkadot bridge pallet.
// TODO: the index is wrong (https://github.com/paritytech/parity-bridges-common/issues/1945)
#[codec(index = 41)]
#[codec(index = 51)]
BridgePolkadotGrandpa(BridgePolkadotGrandpaCall),
/// Polkadot parachain bridge pallet.
// TODO: the index is wrong (https://github.com/paritytech/parity-bridges-common/issues/1945)
#[codec(index = 42)]
#[codec(index = 52)]
BridgePolkadotParachain(BridgeParachainCall),
/// Polkadot messages bridge pallet.
// TODO: the index is wrong (https://github.com/paritytech/parity-bridges-common/issues/1945)
#[codec(index = 46)]
#[codec(index = 53)]
BridgePolkadotMessages(BridgePolkadotMessagesCall),
}

Expand Down
11 changes: 4 additions & 7 deletions relays/client-bridge-hub-polkadot/src/runtime_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,13 @@ pub enum Call {
Utility(UtilityCall<Call>),

/// Kusama bridge pallet.
// TODO: the index is wrong (https://github.com/paritytech/parity-bridges-common/issues/1945)
#[codec(index = 43)]
#[codec(index = 51)]
BridgeKusamaGrandpa(BridgeKusamaGrandpaCall),
/// Kusama parachain bridge pallet.
// TODO: the index is wrong (https://github.com/paritytech/parity-bridges-common/issues/1945)
#[codec(index = 44)]
#[codec(index = 52)]
BridgeKusamaParachain(BridgeParachainCall),
/// Kusama messages bridge pallet.
// TODO: the index is wrong (https://github.com/paritytech/parity-bridges-common/issues/1945)
#[codec(index = 45)]
#[codec(index = 53)]
BridgeKusamaMessages(BridgeKusamaMessagesCall),
}

Expand Down Expand Up @@ -114,6 +111,6 @@ mod tests {

// encode call as hex string
let hex_encoded_call = format!("0x{:?}", HexDisplay::from(&Encode::encode(&tx)));
assert_eq!(hex_encoded_call, "0x2b01ae4a25acf250d72ed02c149ecc7dd3c9ee976d41a2888fc551de8064521dc01d2d0192b965f0656a4e0e5fc0167da2d4b5ee72b3be2c1583c4c1e5236c8c12aa141bd2c0afaab32de0cb8f7f0d89217e37c5ea302c1ffb5a7a83e10d20f12c32874d0000060000000000000000");
assert_eq!(hex_encoded_call, "0x3301ae4a25acf250d72ed02c149ecc7dd3c9ee976d41a2888fc551de8064521dc01d2d0192b965f0656a4e0e5fc0167da2d4b5ee72b3be2c1583c4c1e5236c8c12aa141bd2c0afaab32de0cb8f7f0d89217e37c5ea302c1ffb5a7a83e10d20f12c32874d0000060000000000000000");
}
}
1 change: 0 additions & 1 deletion relays/client-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ impl ChainWithBalances for Kusama {

impl RelayChain for Kusama {
const PARAS_PALLET_NAME: &'static str = bp_kusama::PARAS_PALLET_NAME;
// TODO: check me (https://github.com/paritytech/parity-bridges-common/issues/1945)
const PARACHAINS_FINALITY_PALLET_NAME: &'static str = "BridgeKusamaParachain";
}
1 change: 0 additions & 1 deletion relays/client-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ impl ChainWithBalances for Polkadot {

impl RelayChain for Polkadot {
const PARAS_PALLET_NAME: &'static str = bp_polkadot::PARAS_PALLET_NAME;
// TODO: check me (https://github.com/paritytech/parity-bridges-common/issues/1945)
const PARACHAINS_FINALITY_PALLET_NAME: &'static str = "BridgePolkadotParachain";
}

0 comments on commit 696ff1c

Please sign in to comment.