Skip to content
Snippets Groups Projects
Unverified Commit 141a73e5 authored by Branislav Kontur's avatar Branislav Kontur
Browse files

Unnecessary `XcmExportFeeToRelayerRewardAccounts` + more tests fixes

parent ac80f243
Branches
No related merge requests found
......@@ -19,8 +19,6 @@ use super::{
ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
TransactionByteFee, WeightToFee, XcmOverBridgeHubWestend, XcmOverRococoBulletin, XcmpQueue,
};
use bp_messages::LaneId;
use bp_relayers::{PayRewardFromAccount, RewardsAccountOwner, RewardsAccountParams};
use core::marker::PhantomData;
use frame_support::{
......@@ -206,13 +204,6 @@ impl xcm_executor::Config for XcmConfig {
type FeeManager = XcmFeeManagerFromComponentsBridgeHub<
WaivedLocations,
(
XcmExportFeeToRelayerRewardAccounts<
Self::AssetTransactor,
crate::bridge_to_westend_config::WestendGlobalConsensusNetwork,
crate::bridge_to_westend_config::AssetHubWestendParaId,
bp_bridge_hub_westend::BridgeHubWestend,
crate::bridge_to_westend_config::AssetHubRococoToAssetHubWestendMessagesLane,
>,
XcmExportFeeToSibling<
bp_rococo::Balance,
AccountId,
......@@ -293,100 +284,6 @@ impl cumulus_pallet_xcm::Config for Runtime {
type XcmExecutor = XcmExecutor<XcmConfig>;
}
/// A `HandleFee` implementation that simply deposits the fees for `ExportMessage` XCM instructions
/// into the accounts that are used for paying the relayer rewards.
/// Burns the fees in case of a failure.
pub struct XcmExportFeeToRelayerRewardAccounts<
AssetTransactor,
DestNetwork,
DestParaId,
DestBridgedChain,
BridgeLaneId,
>(PhantomData<(AssetTransactor, DestNetwork, DestParaId, DestBridgedChain, BridgeLaneId)>);
impl<
AssetTransactor: TransactAsset,
DestNetwork: Get<NetworkId>,
DestParaId: Get<cumulus_primitives_core::ParaId>,
DestBridgedChain: bp_runtime::Chain,
BridgeLaneId: Get<LaneId>,
> HandleFee
for XcmExportFeeToRelayerRewardAccounts<
AssetTransactor,
DestNetwork,
DestParaId,
DestBridgedChain,
BridgeLaneId,
>
{
fn handle_fee(fee: Assets, maybe_context: Option<&XcmContext>, reason: FeeReason) -> Assets {
if matches!(reason, FeeReason::Export { network: bridged_network, destination }
if bridged_network == DestNetwork::get() &&
destination == [Parachain(DestParaId::get().into())])
{
let bridged_chain_id = DestBridgedChain::ID;
// We have 2 relayer rewards accounts:
// - the SA of the source parachain on this BH: this pays the relayers for delivering
// Source para -> Target Para message delivery confirmations
// - the SA of the destination parachain on this BH: this pays the relayers for
// delivering Target para -> Source Para messages
// We split the `ExportMessage` fee between these 2 accounts.
let source_para_account = PayRewardFromAccount::<
pallet_balances::Pallet<Runtime>,
AccountId,
>::rewards_account(RewardsAccountParams::new(
BridgeLaneId::get(),
bridged_chain_id,
RewardsAccountOwner::ThisChain,
));
let dest_para_account = PayRewardFromAccount::<
pallet_balances::Pallet<Runtime>,
AccountId,
>::rewards_account(RewardsAccountParams::new(
BridgeLaneId::get(),
bridged_chain_id,
RewardsAccountOwner::BridgedChain,
));
for asset in fee.into_inner() {
match asset.fun {
Fungible(total_fee) => {
let source_fee = total_fee / 2;
deposit_or_burn_fee::<AssetTransactor>(
Asset { id: asset.id.clone(), fun: Fungible(source_fee) }.into(),
maybe_context,
AccountId32 { network: None, id: source_para_account.clone().into() }
.into(),
);
let dest_fee = total_fee - source_fee;
deposit_or_burn_fee::<AssetTransactor>(
Asset { id: asset.id, fun: Fungible(dest_fee) }.into(),
maybe_context,
AccountId32 { network: None, id: dest_para_account.clone().into() }
.into(),
);
},
NonFungible(_) => {
deposit_or_burn_fee::<AssetTransactor>(
asset.into(),
maybe_context,
AccountId32 { network: None, id: source_para_account.clone().into() }
.into(),
);
},
}
}
return Assets::new()
}
fee
}
}
pub struct XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, HandleFee>(
PhantomData<(WaivedLocations, HandleFee)>,
);
......
......@@ -358,7 +358,7 @@ mod bridge_hub_westend_tests {
_ => None,
}
}),
|| XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND,
|| (),
)
}
......@@ -600,7 +600,7 @@ mod bridge_hub_bulletin_tests {
_ => None,
}
}),
|| XCM_LANE_FOR_ROCOCO_PEOPLE_TO_ROCOCO_BULLETIN,
|| (),
)
}
......
......@@ -256,7 +256,7 @@ fn message_dispatch_routing_works() {
_ => None,
}
}),
|| XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO,
|| (),
)
}
......
......@@ -434,7 +434,7 @@ pub fn message_dispatch_routing_works<
unwrap_cumulus_pallet_xcmp_queue_event: Box<
dyn Fn(Vec<u8>) -> Option<cumulus_pallet_xcmp_queue::Event<Runtime>>,
>,
prepare_configuration: impl Fn() -> LaneId,
prepare_configuration: impl Fn(),
) where
Runtime: BasicParachainRuntime
+ cumulus_pallet_xcmp_queue::Config
......@@ -462,8 +462,9 @@ pub fn message_dispatch_routing_works<
assert_ne!(runtime_para_id, sibling_parachain_id);
run_test::<Runtime, _>(collator_session_key, runtime_para_id, vec![], || {
let expected_lane_id = prepare_configuration();
prepare_configuration();
let dummy_lane_id = LaneId::new(1, 2);
let mut alice = [0u8; 32];
alice[0] = 1;
......@@ -480,7 +481,7 @@ pub fn message_dispatch_routing_works<
>((RuntimeNetwork::get(), Here));
let result =
<<Runtime as BridgeMessagesConfig<MessagesPalletInstance>>::MessageDispatch>::dispatch(
test_data::dispatch_message(expected_lane_id, 1, bridging_message),
test_data::dispatch_message(dummy_lane_id, 1, bridging_message),
);
assert_eq!(
format!("{:?}", result.dispatch_level_result),
......@@ -508,7 +509,7 @@ pub fn message_dispatch_routing_works<
let result =
<<Runtime as BridgeMessagesConfig<MessagesPalletInstance>>::MessageDispatch>::dispatch(
DispatchMessage {
key: MessageKey { lane_id: expected_lane_id, nonce: 1 },
key: MessageKey { lane_id: dummy_lane_id, nonce: 1 },
data: DispatchMessageData { payload: Ok(bridging_message.clone()) },
},
);
......@@ -540,7 +541,7 @@ pub fn message_dispatch_routing_works<
let result =
<<Runtime as BridgeMessagesConfig<MessagesPalletInstance>>::MessageDispatch>::dispatch(
DispatchMessage {
key: MessageKey { lane_id: expected_lane_id, nonce: 1 },
key: MessageKey { lane_id: dummy_lane_id, nonce: 1 },
data: DispatchMessageData { payload: Ok(bridging_message) },
},
);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment