Skip to content

Commit

Permalink
Showing 96 changed files with 2,764 additions and 1,491 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

11 changes: 3 additions & 8 deletions bridges/bin/runtime-common/src/extensions.rs
Original file line number Diff line number Diff line change
@@ -374,7 +374,7 @@ mod tests {
use super::*;
use crate::mock::*;
use bp_header_chain::StoredHeaderDataBuilder;
use bp_messages::{InboundLaneData, LaneId, MessageNonce, OutboundLaneData};
use bp_messages::{InboundLaneData, MessageNonce, OutboundLaneData};
use bp_parachains::{BestParaHeadHash, ParaInfo};
use bp_polkadot_core::parachains::{ParaHeadsProof, ParaId};
use bp_relayers::{RewardsAccountOwner, RewardsAccountParams};
@@ -390,17 +390,16 @@ mod tests {
};

parameter_types! {
pub MsgProofsRewardsAccount: RewardsAccountParams = RewardsAccountParams::new(
pub MsgProofsRewardsAccount: RewardsAccountParams<TestLaneIdType> = RewardsAccountParams::new(
test_lane_id(),
TEST_BRIDGED_CHAIN_ID,
RewardsAccountOwner::ThisChain,
);
pub MsgDeliveryProofsRewardsAccount: RewardsAccountParams = RewardsAccountParams::new(
pub MsgDeliveryProofsRewardsAccount: RewardsAccountParams<TestLaneIdType> = RewardsAccountParams::new(
test_lane_id(),
TEST_BRIDGED_CHAIN_ID,
RewardsAccountOwner::BridgedChain,
);
pub TestLaneId: LaneId = test_lane_id();
}

pub struct MockCall {
@@ -476,10 +475,6 @@ mod tests {
}
}

fn test_lane_id() -> LaneId {
LaneId::new(1, 2)
}

fn initial_balance_of_relayer_account_at_this_chain() -> ThisChainBalance {
let test_stake: ThisChainBalance = TestStake::get();
ExistentialDeposit::get().saturating_add(test_stake * 100)
8 changes: 3 additions & 5 deletions bridges/bin/runtime-common/src/messages_api.rs
Original file line number Diff line number Diff line change
@@ -16,14 +16,12 @@

//! Helpers for implementing various message-related runtime API methods.
use bp_messages::{
InboundMessageDetails, LaneId, MessageNonce, MessagePayload, OutboundMessageDetails,
};
use bp_messages::{InboundMessageDetails, MessageNonce, MessagePayload, OutboundMessageDetails};
use sp_std::vec::Vec;

/// Implementation of the `To*OutboundLaneApi::message_details`.
pub fn outbound_message_details<Runtime, MessagesPalletInstance>(
lane: LaneId,
lane: Runtime::LaneId,
begin: MessageNonce,
end: MessageNonce,
) -> Vec<OutboundMessageDetails>
@@ -48,7 +46,7 @@ where

/// Implementation of the `To*InboundLaneApi::message_details`.
pub fn inbound_message_details<Runtime, MessagesPalletInstance>(
lane: LaneId,
lane: Runtime::LaneId,
messages: Vec<(MessagePayload, OutboundMessageDetails)>,
) -> Vec<InboundMessageDetails>
where
78 changes: 43 additions & 35 deletions bridges/bin/runtime-common/src/messages_benchmarking.rs
Original file line number Diff line number Diff line change
@@ -33,15 +33,15 @@ use pallet_bridge_messages::{
encode_all_messages, encode_lane_data, prepare_message_delivery_storage_proof,
prepare_messages_storage_proof,
},
BridgedChainOf, ThisChainOf,
BridgedChainOf, LaneIdOf, ThisChainOf,
};
use sp_runtime::traits::{Header, Zero};
use sp_std::prelude::*;
use xcm::latest::prelude::*;

/// Prepare inbound bridge message according to given message proof parameters.
fn prepare_inbound_message(
params: &MessageProofParams,
fn prepare_inbound_message<LaneId>(
params: &MessageProofParams<LaneId>,
successful_dispatch_message_generator: impl Fn(usize) -> MessagePayload,
) -> MessagePayload {
let expected_size = params.proof_params.db_size.unwrap_or(0) as usize;
@@ -71,9 +71,9 @@ fn prepare_inbound_message(
/// uses GRANDPA finality. For parachains, please use the `prepare_message_proof_from_parachain`
/// function.
pub fn prepare_message_proof_from_grandpa_chain<R, FI, MI>(
params: MessageProofParams,
params: MessageProofParams<LaneIdOf<R, MI>>,
message_generator: impl Fn(usize) -> MessagePayload,
) -> (FromBridgedChainMessagesProof<HashOf<BridgedChainOf<R, MI>>>, Weight)
) -> (FromBridgedChainMessagesProof<HashOf<BridgedChainOf<R, MI>>, LaneIdOf<R, MI>>, Weight)
where
R: pallet_bridge_grandpa::Config<FI, BridgedChain = BridgedChainOf<R, MI>>
+ pallet_bridge_messages::Config<
@@ -84,18 +84,21 @@ where
MI: 'static,
{
// prepare storage proof
let (state_root, storage_proof) =
prepare_messages_storage_proof::<BridgedChainOf<R, MI>, ThisChainOf<R, MI>>(
params.lane,
params.message_nonces.clone(),
params.outbound_lane_data.clone(),
params.proof_params,
|_| prepare_inbound_message(&params, &message_generator),
encode_all_messages,
encode_lane_data,
false,
false,
);
let (state_root, storage_proof) = prepare_messages_storage_proof::<
BridgedChainOf<R, MI>,
ThisChainOf<R, MI>,
LaneIdOf<R, MI>,
>(
params.lane,
params.message_nonces.clone(),
params.outbound_lane_data.clone(),
params.proof_params,
|_| prepare_inbound_message(&params, &message_generator),
encode_all_messages,
encode_lane_data,
false,
false,
);

// update runtime storage
let (_, bridged_header_hash) = insert_header_to_grandpa_pallet::<R, FI>(state_root);
@@ -121,28 +124,31 @@ where
/// uses parachain finality. For GRANDPA chains, please use the
/// `prepare_message_proof_from_grandpa_chain` function.
pub fn prepare_message_proof_from_parachain<R, PI, MI>(
params: MessageProofParams,
params: MessageProofParams<LaneIdOf<R, MI>>,
message_generator: impl Fn(usize) -> MessagePayload,
) -> (FromBridgedChainMessagesProof<HashOf<BridgedChainOf<R, MI>>>, Weight)
) -> (FromBridgedChainMessagesProof<HashOf<BridgedChainOf<R, MI>>, LaneIdOf<R, MI>>, Weight)
where
R: pallet_bridge_parachains::Config<PI> + pallet_bridge_messages::Config<MI>,
PI: 'static,
MI: 'static,
BridgedChainOf<R, MI>: Chain<Hash = ParaHash> + Parachain,
{
// prepare storage proof
let (state_root, storage_proof) =
prepare_messages_storage_proof::<BridgedChainOf<R, MI>, ThisChainOf<R, MI>>(
params.lane,
params.message_nonces.clone(),
params.outbound_lane_data.clone(),
params.proof_params,
|_| prepare_inbound_message(&params, &message_generator),
encode_all_messages,
encode_lane_data,
false,
false,
);
let (state_root, storage_proof) = prepare_messages_storage_proof::<
BridgedChainOf<R, MI>,
ThisChainOf<R, MI>,
LaneIdOf<R, MI>,
>(
params.lane,
params.message_nonces.clone(),
params.outbound_lane_data.clone(),
params.proof_params,
|_| prepare_inbound_message(&params, &message_generator),
encode_all_messages,
encode_lane_data,
false,
false,
);

// update runtime storage
let (_, bridged_header_hash) =
@@ -166,8 +172,8 @@ where
/// uses GRANDPA finality. For parachains, please use the
/// `prepare_message_delivery_proof_from_parachain` function.
pub fn prepare_message_delivery_proof_from_grandpa_chain<R, FI, MI>(
params: MessageDeliveryProofParams<AccountIdOf<ThisChainOf<R, MI>>>,
) -> FromBridgedChainMessagesDeliveryProof<HashOf<BridgedChainOf<R, MI>>>
params: MessageDeliveryProofParams<AccountIdOf<ThisChainOf<R, MI>>, LaneIdOf<R, MI>>,
) -> FromBridgedChainMessagesDeliveryProof<HashOf<BridgedChainOf<R, MI>>, LaneIdOf<R, MI>>
where
R: pallet_bridge_grandpa::Config<FI, BridgedChain = BridgedChainOf<R, MI>>
+ pallet_bridge_messages::Config<
@@ -182,6 +188,7 @@ where
let (state_root, storage_proof) = prepare_message_delivery_storage_proof::<
BridgedChainOf<R, MI>,
ThisChainOf<R, MI>,
LaneIdOf<R, MI>,
>(params.lane, params.inbound_lane_data, params.proof_params);

// update runtime storage
@@ -200,8 +207,8 @@ where
/// uses parachain finality. For GRANDPA chains, please use the
/// `prepare_message_delivery_proof_from_grandpa_chain` function.
pub fn prepare_message_delivery_proof_from_parachain<R, PI, MI>(
params: MessageDeliveryProofParams<AccountIdOf<ThisChainOf<R, MI>>>,
) -> FromBridgedChainMessagesDeliveryProof<HashOf<BridgedChainOf<R, MI>>>
params: MessageDeliveryProofParams<AccountIdOf<ThisChainOf<R, MI>>, LaneIdOf<R, MI>>,
) -> FromBridgedChainMessagesDeliveryProof<HashOf<BridgedChainOf<R, MI>>, LaneIdOf<R, MI>>
where
R: pallet_bridge_parachains::Config<PI> + pallet_bridge_messages::Config<MI>,
PI: 'static,
@@ -213,6 +220,7 @@ where
let (state_root, storage_proof) = prepare_message_delivery_storage_proof::<
BridgedChainOf<R, MI>,
ThisChainOf<R, MI>,
LaneIdOf<R, MI>,
>(params.lane, params.inbound_lane_data, params.proof_params);

// update runtime storage
29 changes: 17 additions & 12 deletions bridges/bin/runtime-common/src/mock.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
use bp_header_chain::ChainWithGrandpa;
use bp_messages::{
target_chain::{DispatchMessage, MessageDispatch},
ChainWithMessages, LaneId, MessageNonce,
ChainWithMessages, HashedLaneId, LaneIdType, MessageNonce,
};
use bp_parachains::SingleParaStoredHeaderDataBuilder;
use bp_relayers::PayRewardFromAccount;
@@ -70,7 +70,7 @@ pub type BridgedChainHeader =
sp_runtime::generic::Header<BridgedChainBlockNumber, BridgedChainHasher>;

/// Rewards payment procedure.
pub type TestPaymentProcedure = PayRewardFromAccount<Balances, ThisChainAccountId>;
pub type TestPaymentProcedure = PayRewardFromAccount<Balances, ThisChainAccountId, TestLaneIdType>;
/// Stake that we are using in tests.
pub type TestStake = ConstU64<5_000>;
/// Stake and slash mechanism to use in tests.
@@ -83,10 +83,11 @@ pub type TestStakeAndSlash = pallet_bridge_relayers::StakeAndSlashNamed<
ConstU32<8>,
>;

/// Message lane used in tests.
#[allow(unused)]
pub fn test_lane_id() -> LaneId {
LaneId::new(1, 2)
/// Lane identifier type used for tests.
pub type TestLaneIdType = HashedLaneId;
/// Lane that we're using in tests.
pub fn test_lane_id() -> TestLaneIdType {
TestLaneIdType::try_new(1, 2).unwrap()
}

/// Bridged chain id used in tests.
@@ -189,10 +190,10 @@ impl pallet_bridge_messages::Config for TestRuntime {
type WeightInfo = pallet_bridge_messages::weights::BridgeWeight<TestRuntime>;

type OutboundPayload = Vec<u8>;

type InboundPayload = Vec<u8>;
type DeliveryPayments = ();
type LaneId = TestLaneIdType;

type DeliveryPayments = ();
type DeliveryConfirmationPayments = pallet_bridge_relayers::DeliveryConfirmationPaymentsAdapter<
TestRuntime,
(),
@@ -213,32 +214,36 @@ impl pallet_bridge_relayers::Config for TestRuntime {
type PaymentProcedure = TestPaymentProcedure;
type StakeAndSlash = TestStakeAndSlash;
type WeightInfo = ();
type LaneId = TestLaneIdType;
}

/// Dummy message dispatcher.
pub struct DummyMessageDispatch;

impl DummyMessageDispatch {
pub fn deactivate(lane: LaneId) {
pub fn deactivate(lane: TestLaneIdType) {
frame_support::storage::unhashed::put(&(b"inactive", lane).encode()[..], &false);
}
}

impl MessageDispatch for DummyMessageDispatch {
type DispatchPayload = Vec<u8>;
type DispatchLevelResult = ();
type LaneId = TestLaneIdType;

fn is_active(lane: LaneId) -> bool {
fn is_active(lane: Self::LaneId) -> bool {
frame_support::storage::unhashed::take::<bool>(&(b"inactive", lane).encode()[..]) !=
Some(false)
}

fn dispatch_weight(_message: &mut DispatchMessage<Self::DispatchPayload>) -> Weight {
fn dispatch_weight(
_message: &mut DispatchMessage<Self::DispatchPayload, Self::LaneId>,
) -> Weight {
Weight::zero()
}

fn dispatch(
_: DispatchMessage<Self::DispatchPayload>,
_: DispatchMessage<Self::DispatchPayload, Self::LaneId>,
) -> MessageDispatchResult<Self::DispatchLevelResult> {
MessageDispatchResult { unspent_weight: Weight::zero(), dispatch_level_result: () }
}
2 changes: 1 addition & 1 deletion bridges/chains/chain-bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
@@ -93,4 +93,4 @@ pub const WITH_BRIDGE_HUB_KUSAMA_MESSAGES_PALLET_NAME: &str = "BridgeKusamaMessa
pub const WITH_BRIDGE_HUB_KUSAMA_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";

decl_bridge_finality_runtime_apis!(bridge_hub_kusama);
decl_bridge_messages_runtime_apis!(bridge_hub_kusama);
decl_bridge_messages_runtime_apis!(bridge_hub_kusama, LegacyLaneId);
2 changes: 1 addition & 1 deletion bridges/chains/chain-bridge-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -85,4 +85,4 @@ pub const WITH_BRIDGE_HUB_POLKADOT_MESSAGES_PALLET_NAME: &str = "BridgePolkadotM
pub const WITH_BRIDGE_HUB_POLKADOT_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";

decl_bridge_finality_runtime_apis!(bridge_hub_polkadot);
decl_bridge_messages_runtime_apis!(bridge_hub_polkadot);
decl_bridge_messages_runtime_apis!(bridge_hub_polkadot, LegacyLaneId);
2 changes: 1 addition & 1 deletion bridges/chains/chain-bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -99,7 +99,7 @@ pub const WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX: u8 = 51;
pub const WITH_BRIDGE_ROCOCO_TO_BULLETIN_MESSAGES_PALLET_INDEX: u8 = 61;

decl_bridge_finality_runtime_apis!(bridge_hub_rococo);
decl_bridge_messages_runtime_apis!(bridge_hub_rococo);
decl_bridge_messages_runtime_apis!(bridge_hub_rococo, LegacyLaneId);

frame_support::parameter_types! {
/// The XCM fee that is paid for executing XCM program (with `ExportMessage` instruction) at the Rococo
2 changes: 1 addition & 1 deletion bridges/chains/chain-bridge-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ pub const WITH_BRIDGE_HUB_WESTEND_RELAYERS_PALLET_NAME: &str = "BridgeRelayers";
pub const WITH_BRIDGE_WESTEND_TO_ROCOCO_MESSAGES_PALLET_INDEX: u8 = 44;

decl_bridge_finality_runtime_apis!(bridge_hub_westend);
decl_bridge_messages_runtime_apis!(bridge_hub_westend);
decl_bridge_messages_runtime_apis!(bridge_hub_westend, LegacyLaneId);

frame_support::parameter_types! {
/// The XCM fee that is paid for executing XCM program (with `ExportMessage` instruction) at the Westend
2 changes: 1 addition & 1 deletion bridges/chains/chain-polkadot-bulletin/src/lib.rs
Original file line number Diff line number Diff line change
@@ -228,4 +228,4 @@ impl ChainWithMessages for PolkadotBulletin {
}

decl_bridge_finality_runtime_apis!(polkadot_bulletin, grandpa);
decl_bridge_messages_runtime_apis!(polkadot_bulletin);
decl_bridge_messages_runtime_apis!(polkadot_bulletin, bp_messages::HashedLaneId);
Loading

0 comments on commit 5f342c8

Please sign in to comment.