Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bridges lane id agnostic for backwards compatibility #5649

Merged
merged 47 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1994378
Removed `pallet::getter`
bkontur Sep 2, 2024
1333603
xcm-executor doc nits
bkontur Sep 2, 2024
b24e92b
Better log
bkontur Sep 3, 2024
af658ce
Renamed AdminOrigin to ForceOrigin
bkontur Sep 3, 2024
f95b114
Add optional laneId to genesis config + open AHR<>AHW for local genesis
bkontur Sep 4, 2024
8061876
Fix metrics labels
bkontur Sep 4, 2024
bcad8a2
Fix `LaneId` encode/decode for backwards compatibility
bkontur Sep 4, 2024
df91ef2
Lets see BridgeId in the logs
bkontur Sep 6, 2024
e9fc6eb
Make `LaneId` generic for backwards compatibility
bkontur Sep 6, 2024
9c55ad7
Generic `LaneId` for `pallet_bridge_messages`
bkontur Sep 8, 2024
4c52f86
Generic `LaneId` for `pallet_xcm_bridge_hub`
bkontur Sep 9, 2024
17d3681
Generic `LaneId` for `pallet_bridge_relayers`
bkontur Sep 16, 2024
387f5ea
Generic `LaneId` for `bridge-runtime-common`
bkontur Sep 17, 2024
cdbddfa
Generic `LaneId` for relayer code
bkontur Sep 17, 2024
387ae67
Add multi-instance support for `pallet_bridge_relayers`
bkontur Sep 18, 2024
c1ec789
Rewards migraiton for `pallet_bridge_relayers`
bkontur Sep 18, 2024
e1f09f3
Adjust testnet runtimes to the latest vogue
bkontur Sep 19, 2024
4835750
Adjust tests with latest vogue
bkontur Sep 19, 2024
bebaba1
Testing nits
bkontur Sep 20, 2024
ded26ef
zepter+taplo
bkontur Sep 20, 2024
8de9f0c
prdoc draft
bkontur Sep 20, 2024
9d74ecb
prdoc
bkontur Sep 20, 2024
69357e6
Deduplicate functionality
bkontur Sep 20, 2024
ba33d24
Fix for zombienet-bridges-0001-asset-transfer-works
bkontur Sep 22, 2024
c084d60
Merge remote-tracking branch 'origin/master' into bko-bridges-lane-id…
bkontur Sep 22, 2024
fad96d9
clippy
bkontur Sep 22, 2024
268a7a7
clippy
bkontur Sep 22, 2024
f89581f
Fix bridges integration tests - open AHR<>AHW lanes for genesis
bkontur Sep 22, 2024
c2989e0
Fixed migration for BridgeHubRococo/Westend
bkontur Sep 22, 2024
58aafd2
Merge remote-tracking branch 'origin/master' into bko-bridges-lane-id…
bkontur Sep 22, 2024
7bace0d
Merge remote-tracking branch 'origin/master' into bko-bridges-lane-id…
bkontur Sep 23, 2024
93a789a
Exporter nits
bkontur Sep 23, 2024
962e141
Merge remote-tracking branch 'origin/master' into bko-bridges-lane-id…
bkontur Sep 23, 2024
3ae8d31
Update bridges/modules/relayers/src/extension/mod.rs
bkontur Sep 24, 2024
8e6e33a
prdoc major -> minor
bkontur Sep 24, 2024
6ccc9c5
Removed forgotten TODO
bkontur Sep 24, 2024
e3f212b
Merge remote-tracking branch 'origin/master' into bko-bridges-lane-id…
bkontur Sep 24, 2024
98aedb2
Missing instance support for rewards + Bulletin without rewards + Has…
bkontur Sep 24, 2024
444c12a
Merge remote-tracking branch 'origin/bko-bridges-lane-id-agnostic' in…
bkontur Sep 24, 2024
2f8a0fc
prdoc
bkontur Sep 24, 2024
b545648
prdoc
bkontur Sep 24, 2024
4daae21
Review fixes - part1
bkontur Sep 24, 2024
7a6cc8d
Review nits
bkontur Sep 24, 2024
11789c1
Merge remote-tracking branch 'origin/master' into bko-bridges-lane-id…
bkontur Sep 24, 2024
e0c77ca
Merge branch 'master' into bko-bridges-lane-id-agnostic
bkontur Sep 24, 2024
2f24d48
fix prdoc
ggwpez Sep 24, 2024
2bb151b
Merge branch 'master' into bko-bridges-lane-id-agnostic
bkontur Sep 24, 2024
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
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
Expand Up @@ -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};
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions bridges/bin/runtime-common/src/messages_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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
Expand Down
78 changes: 43 additions & 35 deletions bridges/bin/runtime-common/src/messages_benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<
Expand All @@ -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);
Expand All @@ -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) =
Expand All @@ -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<
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
29 changes: 17 additions & 12 deletions bridges/bin/runtime-common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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::new(1, 2)
}

/// Bridged chain id used in tests.
Expand Down Expand Up @@ -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,
(),
Expand All @@ -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: () }
}
Expand Down
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
Expand Up @@ -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
Expand Up @@ -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
Expand Up @@ -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
Expand Down
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
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bridges/chains/chain-polkadot-bulletin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading