From 1da09f047a50b3ab722c01574dc8d6ff28d18237 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 4 Sep 2023 12:48:07 +0200 Subject: [PATCH] Extended Kusama/Polkadot BridgeHub configuration with dynamic fees support Squashed commit of the following: commit fcb61370cd65b3579675b3a3d20c42475176756b Merge: 8e21f41ca1 a7402efd77 Author: Branislav Kontur Date: Sun Sep 3 11:31:18 2023 +0200 Merge branch 'bridge-hub-kusama-polkadot' into bridge-hub-kusama-polkadot-with-dynamic-fees commit 8e21f41ca1a69a60e4a0bf6d8e2f5238e4f81a07 Merge: ca288257c8 69db677180 Author: Branislav Kontur Date: Thu Aug 17 09:55:18 2023 +0200 Merge remote-tracking branch 'origin/bridge-hub-kusama-polkadot' into bridge-hub-kusama-polkadot-with-dynamic-fees commit ca288257c8edb39453945267022c789e6d343a6a Merge: 7824adb44c d701b6ad24 Author: Branislav Kontur Date: Wed Aug 16 21:36:16 2023 +0200 Merge remote-tracking branch 'origin/bridge-hub-kusama-polkadot' into bridge-hub-kusama-polkadot-with-dynamic-fees commit 7824adb44c35aba4e8334496c5c1e8c7aab2d510 Author: Branislav Kontur Date: Wed Aug 16 12:36:06 2023 +0200 Added consts for base fee with sanity check commit 47addc3fd6ab5518610c5a3c15a615b520def45f Author: Branislav Kontur Date: Wed Aug 16 12:28:46 2023 +0200 Fix for BHRo/Wo commit ad6f236fec91b04acb16a58c9eabb32a854be57b Author: Branislav Kontur Date: Wed Aug 16 11:50:06 2023 +0200 Congestion messages as Optional to turn on/off `supports_congestion_detection` commit 5931a57af12399ee400f2b31ccacfbdbf7d317b4 Author: Branislav Kontur Date: Wed Aug 16 11:48:42 2023 +0200 Introduced base delivery fee constants commit 4c5e054b998e8d8d8f5df702300ad8ba84ef15fc Author: Branislav Kontur Date: Tue Aug 15 17:35:24 2023 +0200 Adjusted `require_max_weight` with XcmBridgeHubRouterTransactCallMaxWeight commit a9b4637d06e88f859c7dde23566e480d74234eec Author: Branislav Kontur Date: Tue Aug 15 17:26:59 2023 +0200 Added const for `XcmBridgeHubRouterTransactCallMaxWeight` commit 16ac9a1a0c38caee65c8f82531df4230158afcfe Author: Branislav Kontur Date: Tue Aug 15 12:49:03 2023 +0200 Add impl for `CongestedMessage/UncongestedMessage` for BridgeHubs commit 307654e59a491eb1a28e6c650181a7df6c336811 Author: Branislav Kontur Date: Tue Aug 15 12:05:40 2023 +0200 Added XcmBridgeHubRouterCall::report_bridge_status encodings for AHK/P commit 9daeb8b87ea2a404ace4f4acba716d7a9a133a6f Author: Branislav Kontur Date: Mon Aug 14 22:41:38 2023 +0200 Extended script for local run BHK/P commit 983eb8d5990758857529de109282130f2db8ff13 Author: Branislav Kontur Date: Mon Aug 14 16:34:02 2023 +0200 Disabled `UnpaidExecution` for system parachains commit 3a5dfe2fc154fc5e5df6ce1a51fdbe850c73a41e Author: Branislav Kontur Date: Mon Aug 14 16:15:55 2023 +0200 Adjusted test `handle_export_message_from_system_parachain_to_outbound_queue_works` for Paid or Unpaid scenario commit a701215a9b0bcacb151d5c72668f7acb74962d68 Author: Branislav Kontur Date: Mon Aug 14 15:26:28 2023 +0200 Test for calculating base delivery fee on BridgeHubs commit ebc0ed144699ea6c03d43aa17b90458cce15e284 Author: Branislav Kontur Date: Sat Aug 12 16:39:10 2023 +0200 Update to new version with dynamic fees commit 76115f6c759a851df3c837d3c0aa6ceb91aef2c8 Author: Branislav Kontur Date: Fri Aug 11 22:19:45 2023 +0200 [dynfees] Implemented `XcmChannelStatusProvider` for `XcmpQueue` commit e5ac886647f732330defc2c681502a1540e96d98 Author: Branislav Kontur Date: Fri Aug 11 10:03:21 2023 +0200 [dynfees] Rococo/Wococo does not need congestion and dynamic fees (for now) commit 4d60d0992c2da0ff5c84ff899123f3c9b33c3050 Merge: e1d0001ecf 02e00e6411 Author: Branislav Kontur Date: Thu Aug 10 15:58:59 2023 +0200 Merge commit '02e00e6411c56bc44497bcd05104b17cdfdc0862' into bridge-hub-kusama-polkadot-with-dynamic-fees commit 02e00e6411c56bc44497bcd05104b17cdfdc0862 Author: Branislav Kontur Date: Thu Aug 10 15:58:59 2023 +0200 Squashed 'bridges/' changes from edf33a2c85..8f86ec78b7 8f86ec78b7 ".git/.scripts/commands/fmt/fmt.sh" ccf2f9483b Merge remote-tracking branch 'origin/polkadot-staging' into dynamic-fees-v1 f822ebc450 Dynamic fees v1: report congestion status to sending chain (#2318) add9fb1d53 added/fixed some docs 569a80f233 Rename LocalXcmChannel to XcmChannelStatusProvider (#2319) dc3618a4a5 Clippy e7cab6ab49 (Suggestion) Ability to externalize configuration for `ExporterFor` (#2313) c68467beff fmt 5d76f25311 use saturated_len where possible 7cc1470528 Update modules/xcm-bridge-hub-router/src/lib.rs 8d7a38a409 change log target for xcm bridge router pallet 773f93209f Revert "trigger CI" 48f1ba0323 trigger CI b26aa98d1e fixing spellcheck, clippy and rustdoc c467911a37 add new pallet to verify-pallets-build.sh ed72ebe62b get rid of redundant storage value 522bbc7ec4 benchmarks for pallet-xcm-bridge-hub-router 958243564d extension_reject_call_when_dispatcher_is_inactive 38cd8f3df3 fix other tests in the bridge-runtime-common b75e64fdf7 tests for new logic in the XcmBlobHaulerAdapter 4c741714cb tests for LocalXcmQueueMessageProcessor d99420e14c tests for LocalXcmQueueSuspender 084f551bb6 new tests for logic changes in messages pallet d9515f7317 use LocalXcmChannel in XcmBlobMessageDispatch d9a0c2e468 improvements and tests for palle-xcm-bridge-router c24301374a removed commented code eea610a875 pallet-xcm-bridge-hub-router 1fdac85a14 forbid mesage delivery transactions when the channel between target bridge hub and target asset hub is suspended 3c98c245ac OnMessageDelviered callback 65787da038 LocalXcmQueueManager + more adapters 74b48e2cc3 impl backpressure in the XcmBlobHaulerAdapter git-subtree-dir: bridges git-subtree-split: 8f86ec78b7747ba32807e8691f022edb4ad3040d Co-authored-by: Branislav Kontur Co-authored-by: Adrian Catangiu Co-authored-by: Svyatoslav Nikolsky Co-authored-by: Serban Iorga Signed-off-by: Branislav Kontur Signed-off-by: Adrian Catangiu Signed-off-by: Svyatoslav Nikolsky Signed-off-by: Serban Iorga --- Cargo.lock | 3 + cumulus/pallets/xcmp-queue/Cargo.toml | 2 +- .../bridge-hubs/bridge-hub-kusama/Cargo.toml | 4 +- .../src/bridge_hub_config.rs | 30 +++- .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 20 ++- .../bridge-hub-kusama/src/xcm_config.rs | 11 +- .../bridge-hub-kusama/tests/tests.rs | 25 ++- .../bridge-hub-polkadot/Cargo.toml | 4 +- .../src/bridge_hub_config.rs | 30 +++- .../bridge-hub-polkadot/src/lib.rs | 20 ++- .../bridge-hub-polkadot/src/xcm_config.rs | 18 +-- .../bridge-hub-polkadot/tests/tests.rs | 25 ++- .../bridge-hub-rococo/tests/tests.rs | 8 +- .../bridge-hubs/test-utils/Cargo.toml | 1 + .../bridge-hubs/test-utils/src/test_cases.rs | 151 +++++++++++++++++- 15 files changed, 299 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 13c093bc36491..f8ee9ae4c1230 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1822,6 +1822,7 @@ dependencies = [ name = "bridge-hub-kusama-runtime" version = "0.1.0" dependencies = [ + "bp-asset-hub-kusama", "bp-bridge-hub-kusama", "bp-bridge-hub-polkadot", "bp-header-chain", @@ -1902,6 +1903,7 @@ dependencies = [ name = "bridge-hub-polkadot-runtime" version = "0.1.0" dependencies = [ + "bp-asset-hub-polkadot", "bp-bridge-hub-kusama", "bp-bridge-hub-polkadot", "bp-header-chain", @@ -2120,6 +2122,7 @@ dependencies = [ "sp-io", "sp-keyring", "sp-runtime", + "sp-tracing", "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", diff --git a/cumulus/pallets/xcmp-queue/Cargo.toml b/cumulus/pallets/xcmp-queue/Cargo.toml index 0e6a34ecfe698..2a8b9e48a2aae 100644 --- a/cumulus/pallets/xcmp-queue/Cargo.toml +++ b/cumulus/pallets/xcmp-queue/Cargo.toml @@ -46,7 +46,7 @@ cumulus-pallet-parachain-system = { path = "../parachain-system" } [features] default = [ "std" ] std = [ - "bp-xcm-bridge-hub-router/std", + "bp-xcm-bridge-hub-router?/std", "codec/std", "cumulus-primitives-core/std", "frame-benchmarking?/std", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml index 61a5ec19a71fd..55621a1d7c56a 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -64,7 +64,7 @@ cumulus-pallet-dmp-queue = { path = "../../../../pallets/dmp-queue", default-fea cumulus-pallet-parachain-system = { path = "../../../../pallets/parachain-system", default-features = false, features = ["parameterized-consensus-hook",] } cumulus-pallet-session-benchmarking = { path = "../../../../pallets/session-benchmarking", default-features = false} cumulus-pallet-xcm = { path = "../../../../pallets/xcm", default-features = false } -cumulus-pallet-xcmp-queue = { path = "../../../../pallets/xcmp-queue", default-features = false } +cumulus-pallet-xcmp-queue = { path = "../../../../pallets/xcmp-queue", default-features = false, features = ["bridging"] } cumulus-primitives-core = { path = "../../../../primitives/core", default-features = false } cumulus-primitives-utility = { path = "../../../../primitives/utility", default-features = false } pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } @@ -72,6 +72,7 @@ parachain-info = { path = "../../../pallets/parachain-info", default-features = parachains-common = { path = "../../../common", default-features = false } # Bridges +bp-asset-hub-kusama = { path = "../../../../bridges/primitives/chain-asset-hub-kusama", default-features = false } bp-bridge-hub-kusama = { path = "../../../../bridges/primitives/chain-bridge-hub-kusama", default-features = false } bp-bridge-hub-polkadot = { path = "../../../../bridges/primitives/chain-bridge-hub-polkadot", default-features = false } bp-header-chain = { path = "../../../../bridges/primitives/header-chain", default-features = false } @@ -97,6 +98,7 @@ sp-keyring = { path = "../../../../../substrate/primitives/keyring" } [features] default = [ "std" ] std = [ + "bp-asset-hub-kusama/std", "bp-bridge-hub-kusama/std", "bp-bridge-hub-polkadot/std", "bp-header-chain/std", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/bridge_hub_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/bridge_hub_config.rs index 51fbd6e3bac99..7d973c2cebade 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/bridge_hub_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/bridge_hub_config.rs @@ -33,6 +33,7 @@ use bridge_runtime_common::{ RefundableParachain, }, }; +use codec::Encode; use frame_support::{parameter_types, traits::PalletInfoAccess}; use sp_runtime::RuntimeDebug; use xcm::{latest::prelude::*, prelude::NetworkId}; @@ -55,6 +56,28 @@ parameter_types! { ParentThen(X1(Parachain(AssetHubKusamaParaId::get().into()))).into(), ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT_LANE_ID, ); + + pub CongestedMessage: Xcm<()> = sp_std::vec![Transact { + origin_kind: OriginKind::Xcm, + require_weight_at_most: bp_asset_hub_kusama::XcmBridgeHubRouterTransactCallMaxWeight::get(), + call: bp_asset_hub_kusama::Call::ToPolkadotXcmRouter( + bp_asset_hub_kusama::XcmBridgeHubRouterCall::report_bridge_status { + bridge_id: Default::default(), + is_congested: true, + } + ).encode().into(), + }].into(); + + pub UncongestedMessage: Xcm<()> = sp_std::vec![Transact { + origin_kind: OriginKind::Xcm, + require_weight_at_most: bp_asset_hub_kusama::XcmBridgeHubRouterTransactCallMaxWeight::get(), + call: bp_asset_hub_kusama::Call::ToPolkadotXcmRouter( + bp_asset_hub_kusama::XcmBridgeHubRouterCall::report_bridge_status { + bridge_id: Default::default(), + is_congested: false, + } + ).encode().into(), + }].into(); } /// Proof of messages, coming from BridgeHubPolkadot. @@ -81,10 +104,13 @@ impl XcmBlobHauler for ToBridgeHubPolkadotXcmBlobHauler { type SenderAndLane = FromAssetHubKusamaToAssetHubPolkadotRoute; type ToSourceChainSender = crate::XcmRouter; - type CongestedMessage = (); - type UncongestedMessage = (); + type CongestedMessage = CongestedMessage; + type UncongestedMessage = UncongestedMessage; } +/// On messages delivered callback. +pub type OnMessagesDelivered = XcmBlobHaulerAdapter; + /// Messaging Bridge configuration for ThisChain -> BridgeHubPolkadot pub struct WithBridgeHubPolkadotMessageBridge; impl MessageBridge for WithBridgeHubPolkadotMessageBridge { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index 5589d5523d944..daf2b6293ff56 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -493,9 +493,15 @@ impl pallet_bridge_messages::Config for R DeliveryRewardInBalance, >; type SourceHeaderChain = SourceHeaderChainAdapter; - type MessageDispatch = - XcmBlobMessageDispatch, Self::WeightInfo, ()>; - type OnMessagesDelivered = (); + type MessageDispatch = XcmBlobMessageDispatch< + OnThisChainBlobDispatcher, + Self::WeightInfo, + cumulus_pallet_xcmp_queue::bridging::OutboundXcmpChannelCongestionStatusProvider< + bridge_hub_config::AssetHubKusamaParaId, + Runtime, + >, + >; + type OnMessagesDelivered = bridge_hub_config::OnMessagesDelivered; } /// Allows collect and claim rewards for relayers @@ -942,7 +948,11 @@ impl_runtime_apis! { type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - use bridge_runtime_common::messages_benchmarking::{prepare_message_delivery_proof_from_parachain, prepare_message_proof_from_parachain}; + use bridge_runtime_common::messages_benchmarking::{ + generate_xcm_builder_bridge_message_sample, + prepare_message_delivery_proof_from_parachain, + prepare_message_proof_from_parachain + }; use pallet_bridge_messages::benchmarking::{ Config as BridgeMessagesConfig, Pallet as BridgeMessagesBench, @@ -972,7 +982,7 @@ impl_runtime_apis! { Runtime, BridgeGrandpaPolkadotInstance, bridge_hub_config::WithBridgeHubPolkadotMessageBridge, - >(params, X2(GlobalConsensus(xcm_config::RelayNetwork::get().unwrap()), Parachain(42))) + >(params, generate_xcm_builder_bridge_message_sample(X2(GlobalConsensus(xcm_config::RelayNetwork::get().unwrap()), Parachain(42)))) } fn prepare_message_delivery_proof( params: MessageDeliveryProofParams, diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index 028dd5329ca12..7b8e3fa5aada1 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -112,12 +112,6 @@ match_types! { MultiLocation { parents: 1, interior: Here } | MultiLocation { parents: 1, interior: X1(_) } }; - // TODO:check-parameter - (https://github.com/paritytech/parity-bridges-common/issues/2084) - // remove this and extend `AllowExplicitUnpaidExecutionFrom` with "or SystemParachains" once merged https://github.com/paritytech/polkadot/pull/7005 - pub type SystemParachains: impl Contains = { - // Statemine - MultiLocation { parents: 1, interior: X1(Parachain(1000)) } - }; } /// A call filter for the XCM Transact instruction. This is a temporary measure until we properly @@ -191,9 +185,8 @@ pub type Barrier = TrailingSetTopicAsId< // If the message is one that immediately attemps to pay for execution, then // allow it. AllowTopLevelPaidExecutionFrom, - // Parent, its pluralities (i.e. governance bodies) and system parachains get - // free execution. - AllowExplicitUnpaidExecutionFrom<(ParentOrParentsPlurality, SystemParachains)>, + // Parent and its pluralities (i.e. governance bodies) get free execution. + AllowExplicitUnpaidExecutionFrom<(ParentOrParentsPlurality,)>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, ), diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/tests/tests.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/tests/tests.rs index 2f47526d4ea8b..fdcf1ad7d508d 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/tests/tests.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/tests/tests.rs @@ -18,7 +18,7 @@ use bp_polkadot_core::Signature; pub use bridge_hub_kusama_runtime::{ bridge_hub_config, constants::fee::WeightToFee, - xcm_config::{RelayNetwork, XcmConfig}, + xcm_config::{KsmRelayLocation, RelayNetwork, XcmConfig}, AllPalletsWithoutSystem, Balances, BridgeGrandpaPolkadotInstance, BridgeRejectObsoleteHeadersAndMessages, ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, SessionKeys, WithBridgeHubPolkadotMessagesInstance, @@ -184,7 +184,10 @@ fn handle_export_message_from_system_parachain_add_to_outbound_queue_works() { } }), || ExportMessage { network: Polkadot, destination: X1(Parachain(1234)), xcm: Xcm(vec![]) }, - bridge_hub_config::ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT_LANE_ID + bridge_hub_config::ASSET_HUB_KUSAMA_TO_ASSET_HUB_POLKADOT_LANE_ID, + Some((KsmRelayLocation::get(), ExistentialDeposit::get()).into()), + // value should be >= than value generated by `can_calculate_weight_for_paid_export_message_with_reserve_transfer` + Some((KsmRelayLocation::get(), bp_asset_hub_kusama::BridgeHubKusamaBaseFeeInDots::get()).into()), ) } @@ -263,3 +266,21 @@ pub fn complex_relay_extrinsic_works() { construct_and_apply_extrinsic, ); } + +#[test] +pub fn can_calculate_weight_for_paid_export_message_with_reserve_transfer() { + let estimated = bridge_hub_test_utils::test_cases::can_calculate_weight_for_paid_export_message_with_reserve_transfer::< + Runtime, + XcmConfig, + WeightToFee, + >(); + + // check if estimated value is sane + let max_expected = bp_asset_hub_kusama::BridgeHubKusamaBaseFeeInDots::get(); + assert!( + estimated <= max_expected, + "calculated: {:?}, max_expected: {:?}, please adjust `bp_asset_hub_kusama::BridgeHubKusamaBaseFeeInDots` value", + estimated, + max_expected + ); +} diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml index 19c678bc57eb4..8b32b99f479fa 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -64,7 +64,7 @@ cumulus-pallet-dmp-queue = { path = "../../../../pallets/dmp-queue", default-fea cumulus-pallet-parachain-system = { path = "../../../../pallets/parachain-system", default-features = false, features = ["parameterized-consensus-hook",] } cumulus-pallet-session-benchmarking = { path = "../../../../pallets/session-benchmarking", default-features = false} cumulus-pallet-xcm = { path = "../../../../pallets/xcm", default-features = false } -cumulus-pallet-xcmp-queue = { path = "../../../../pallets/xcmp-queue", default-features = false } +cumulus-pallet-xcmp-queue = { path = "../../../../pallets/xcmp-queue", default-features = false, features = ["bridging"] } cumulus-primitives-core = { path = "../../../../primitives/core", default-features = false } cumulus-primitives-utility = { path = "../../../../primitives/utility", default-features = false } pallet-collator-selection = { path = "../../../../pallets/collator-selection", default-features = false } @@ -72,6 +72,7 @@ parachain-info = { path = "../../../pallets/parachain-info", default-features = parachains-common = { path = "../../../common", default-features = false } # Bridges +bp-asset-hub-polkadot = { path = "../../../../bridges/primitives/chain-asset-hub-polkadot", default-features = false } bp-bridge-hub-kusama = { path = "../../../../bridges/primitives/chain-bridge-hub-kusama", default-features = false } bp-bridge-hub-polkadot = { path = "../../../../bridges/primitives/chain-bridge-hub-polkadot", default-features = false } bp-header-chain = { path = "../../../../bridges/primitives/header-chain", default-features = false } @@ -97,6 +98,7 @@ sp-keyring = { path = "../../../../../substrate/primitives/keyring" } [features] default = [ "std" ] std = [ + "bp-asset-hub-polkadot/std", "bp-bridge-hub-kusama/std", "bp-bridge-hub-polkadot/std", "bp-header-chain/std", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/bridge_hub_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/bridge_hub_config.rs index 8414e532f5b7b..26a4a2c2175e3 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/bridge_hub_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/bridge_hub_config.rs @@ -33,6 +33,7 @@ use bridge_runtime_common::{ RefundableParachain, }, }; +use codec::Encode; use frame_support::{parameter_types, traits::PalletInfoAccess}; use sp_runtime::RuntimeDebug; use xcm::{latest::prelude::*, prelude::NetworkId}; @@ -55,6 +56,28 @@ parameter_types! { ParentThen(X1(Parachain(AssetHubPolkadotParaId::get().into()))).into(), ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA_LANE_ID, ); + + pub CongestedMessage: Xcm<()> = sp_std::vec![Transact { + origin_kind: OriginKind::Xcm, + require_weight_at_most: bp_asset_hub_polkadot::XcmBridgeHubRouterTransactCallMaxWeight::get(), + call: bp_asset_hub_polkadot::Call::ToKusamaXcmRouter( + bp_asset_hub_polkadot::XcmBridgeHubRouterCall::report_bridge_status { + bridge_id: Default::default(), + is_congested: true, + } + ).encode().into(), + }].into(); + + pub UncongestedMessage: Xcm<()> = sp_std::vec![Transact { + origin_kind: OriginKind::Xcm, + require_weight_at_most: bp_asset_hub_polkadot::XcmBridgeHubRouterTransactCallMaxWeight::get(), + call: bp_asset_hub_polkadot::Call::ToKusamaXcmRouter( + bp_asset_hub_polkadot::XcmBridgeHubRouterCall::report_bridge_status { + bridge_id: Default::default(), + is_congested: false, + } + ).encode().into(), + }].into(); } /// Proof of messages, coming from BridgeHubKusama. @@ -81,10 +104,13 @@ impl XcmBlobHauler for ToBridgeHubKusamaXcmBlobHauler { type SenderAndLane = FromAssetHubPolkadotToAssetHubKusamaRoute; type ToSourceChainSender = crate::XcmRouter; - type CongestedMessage = (); - type UncongestedMessage = (); + type CongestedMessage = CongestedMessage; + type UncongestedMessage = UncongestedMessage; } +/// On messages delivered callback. +pub type OnMessagesDelivered = XcmBlobHaulerAdapter; + /// Messaging Bridge configuration for ThisChain -> BridgeHubKusama pub struct WithBridgeHubKusamaMessageBridge; impl MessageBridge for WithBridgeHubKusamaMessageBridge { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 3ebef36023330..2cd81e99f0640 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -494,9 +494,15 @@ impl pallet_bridge_messages::Config for Run DeliveryRewardInBalance, >; type SourceHeaderChain = SourceHeaderChainAdapter; - type MessageDispatch = - XcmBlobMessageDispatch, Self::WeightInfo, ()>; - type OnMessagesDelivered = (); + type MessageDispatch = XcmBlobMessageDispatch< + OnThisChainBlobDispatcher, + Self::WeightInfo, + cumulus_pallet_xcmp_queue::bridging::OutboundXcmpChannelCongestionStatusProvider< + bridge_hub_config::AssetHubPolkadotParaId, + Runtime, + >, + >; + type OnMessagesDelivered = bridge_hub_config::OnMessagesDelivered; } /// Allows collect and claim rewards for relayers @@ -943,7 +949,11 @@ impl_runtime_apis! { type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - use bridge_runtime_common::messages_benchmarking::{prepare_message_delivery_proof_from_parachain, prepare_message_proof_from_parachain}; + use bridge_runtime_common::messages_benchmarking::{ + generate_xcm_builder_bridge_message_sample, + prepare_message_delivery_proof_from_parachain, + prepare_message_proof_from_parachain + }; use pallet_bridge_messages::benchmarking::{ Config as BridgeMessagesConfig, Pallet as BridgeMessagesBench, @@ -973,7 +983,7 @@ impl_runtime_apis! { Runtime, BridgeGrandpaKusamaInstance, bridge_hub_config::WithBridgeHubKusamaMessageBridge, - >(params, X2(GlobalConsensus(xcm_config::RelayNetwork::get().unwrap()), Parachain(42))) + >(params, generate_xcm_builder_bridge_message_sample(X2(GlobalConsensus(xcm_config::RelayNetwork::get().unwrap()), Parachain(42)))) } fn prepare_message_delivery_proof( params: MessageDeliveryProofParams, diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index 1880c649f57fa..ab6643995efa8 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -115,14 +115,6 @@ match_types! { pub type FellowsPlurality: impl Contains = { MultiLocation { parents: 1, interior: X2(Parachain(1001), Plurality { id: BodyId::Technical, ..}) } }; - // TODO:check-parameter - (https://github.com/paritytech/parity-bridges-common/issues/2084) - // remove this and extend `AllowExplicitUnpaidExecutionFrom` with "or SystemParachains" once merged https://github.com/paritytech/polkadot/pull/7005 - pub type SystemParachains: impl Contains = { - // Statemint - MultiLocation { parents: 1, interior: X1(Parachain(1000)) } | - // Collectives - MultiLocation { parents: 1, interior: X1(Parachain(1001)) } - }; } /// A call filter for the XCM Transact instruction. This is a temporary measure until we properly @@ -196,13 +188,9 @@ pub type Barrier = TrailingSetTopicAsId< // If the message is one that immediately attemps to pay for execution, then // allow it. AllowTopLevelPaidExecutionFrom, - // Parent, its pluralities (i.e. governance bodies), the Fellows plurality - // and system parachains get free execution. - AllowExplicitUnpaidExecutionFrom<( - ParentOrParentsPlurality, - FellowsPlurality, - SystemParachains, - )>, + // Parent, its pluralities (i.e. governance bodies) and the Fellows plurality + // get free execution. + AllowExplicitUnpaidExecutionFrom<(ParentOrParentsPlurality, FellowsPlurality)>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, ), diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/tests/tests.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/tests/tests.rs index 4766ec959dc3b..3753e35541500 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/tests/tests.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/tests/tests.rs @@ -18,7 +18,7 @@ use bp_polkadot_core::Signature; pub use bridge_hub_polkadot_runtime::{ bridge_hub_config, constants::fee::WeightToFee, - xcm_config::{RelayNetwork, XcmConfig}, + xcm_config::{DotRelayLocation, RelayNetwork, XcmConfig}, AllPalletsWithoutSystem, Balances, BridgeGrandpaKusamaInstance, BridgeRejectObsoleteHeadersAndMessages, ExistentialDeposit, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, SessionKeys, WithBridgeHubKusamaMessagesInstance, @@ -184,7 +184,10 @@ fn handle_export_message_from_system_parachain_add_to_outbound_queue_works() { } }), || ExportMessage { network: Kusama, destination: X1(Parachain(1234)), xcm: Xcm(vec![]) }, - bridge_hub_config::ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA_LANE_ID + bridge_hub_config::ASSET_HUB_POLKADOT_TO_ASSET_HUB_KUSAMA_LANE_ID, + Some((DotRelayLocation::get(), ExistentialDeposit::get()).into()), + // value should be >= than value generated by `can_calculate_weight_for_paid_export_message_with_reserve_transfer` + Some((DotRelayLocation::get(), bp_asset_hub_polkadot::BridgeHubPolkadotBaseFeeInDots::get()).into()), ) } @@ -263,3 +266,21 @@ pub fn complex_relay_extrinsic_works() { construct_and_apply_extrinsic, ); } + +#[test] +pub fn can_calculate_weight_for_paid_export_message_with_reserve_transfer() { + let estimated = bridge_hub_test_utils::test_cases::can_calculate_weight_for_paid_export_message_with_reserve_transfer::< + Runtime, + XcmConfig, + WeightToFee, + >(); + + // check if estimated value is sane + let max_expected = bp_asset_hub_polkadot::BridgeHubPolkadotBaseFeeInDots::get(); + assert!( + estimated <= max_expected, + "calculated: {:?}, max_expected: {:?}, please adjust `bp_asset_hub_polkadot::BridgeHubPolkadotBaseFeeInDots` value", + estimated, + max_expected + ); +} diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs index 44e6df0a87f5f..5cf6e02c97809 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs @@ -192,7 +192,9 @@ mod bridge_hub_rococo_tests { } }), || ExportMessage { network: Wococo, destination: X1(Parachain(1234)), xcm: Xcm(vec![]) }, - bridge_hub_rococo_config::DEFAULT_XCM_LANE_TO_BRIDGE_HUB_WOCOCO + bridge_hub_rococo_config::DEFAULT_XCM_LANE_TO_BRIDGE_HUB_WOCOCO, + None, + None, ) } @@ -371,7 +373,9 @@ mod bridge_hub_wococo_tests { } }), || ExportMessage { network: Rococo, destination: X1(Parachain(4321)), xcm: Xcm(vec![]) }, - bridge_hub_wococo_config::DEFAULT_XCM_LANE_TO_BRIDGE_HUB_ROCOCO + bridge_hub_wococo_config::DEFAULT_XCM_LANE_TO_BRIDGE_HUB_ROCOCO, + None, + None, ) } diff --git a/cumulus/parachains/runtimes/bridge-hubs/test-utils/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/test-utils/Cargo.toml index a6509c58ee210..88cd6e54dd53d 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/test-utils/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/test-utils/Cargo.toml @@ -19,6 +19,7 @@ sp-core = { path = "../../../../../substrate/primitives/core", default-features sp-io = { path = "../../../../../substrate/primitives/io", default-features = false} sp-keyring = { path = "../../../../../substrate/primitives/keyring" } sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} +sp-tracing = { path = "../../../../../substrate/primitives/tracing" } pallet-balances = { path = "../../../../../substrate/frame/balances", default-features = false} pallet-utility = { path = "../../../../../substrate/frame/utility", default-features = false} pallet-session = { path = "../../../../../substrate/frame/session", default-features = false} diff --git a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases.rs b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases.rs index 3ecccc3988f52..125a4bd460ed0 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases.rs @@ -46,10 +46,16 @@ use parachains_runtimes_test_utils::{ }; use sp_core::H256; use sp_keyring::AccountKeyring::*; -use sp_runtime::{traits::Header as HeaderT, AccountId32}; +use sp_runtime::{ + traits::{Header as HeaderT, Zero}, + AccountId32, +}; use xcm::latest::prelude::*; use xcm_builder::DispatchBlobError; -use xcm_executor::XcmExecutor; +use xcm_executor::{ + traits::{TransactAsset, WeightBounds}, + XcmExecutor, +}; // Re-export test_case from assets pub use asset_test_utils::include_teleports_for_native_asset_works; @@ -136,6 +142,8 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works< >, export_message_instruction: fn() -> Instruction, expected_lane_id: LaneId, + existential_deposit: Option, + maybe_paid_export_message: Option, ) where Runtime: frame_system::Config + pallet_balances::Config @@ -169,10 +177,35 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works< ); // prepare `ExportMessage` - let xcm = Xcm(vec![ - UnpaidExecution { weight_limit: Unlimited, check_origin: None }, - export_message_instruction(), - ]); + let xcm = if let Some(fee) = maybe_paid_export_message { + // deposit ED to origin (if needed) + if let Some(ed) = existential_deposit { + XcmConfig::AssetTransactor::deposit_asset( + &ed, + &sibling_parachain_location, + &XcmContext::with_message_id([0; 32]), + ) + .expect("deposited ed"); + } + // deposit fee to origin + XcmConfig::AssetTransactor::deposit_asset( + &fee, + &sibling_parachain_location, + &XcmContext::with_message_id([0; 32]), + ) + .expect("deposited fee"); + + Xcm(vec![ + WithdrawAsset(MultiAssets::from(vec![fee.clone()])), + BuyExecution { fees: fee, weight_limit: Unlimited }, + export_message_instruction(), + ]) + } else { + Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + export_message_instruction(), + ]) + }; // execute XCM let hash = xcm.using_encoded(sp_io::hashing::blake2_256); @@ -799,6 +832,112 @@ pub fn complex_relay_extrinsic_works() -> u128 +where + Runtime: frame_system::Config + pallet_balances::Config, + XcmConfig: xcm_executor::Config, + WeightToFee: frame_support::weights::WeightToFee>, + ::Balance: From + Into, +{ + // data here are not relevant for weighing + let mut xcm = Xcm(vec![ + WithdrawAsset(MultiAssets::from(vec![MultiAsset { + id: Concrete(MultiLocation { parents: 1, interior: Here }), + fun: Fungible(34333299), + }])), + BuyExecution { + fees: MultiAsset { + id: Concrete(MultiLocation { parents: 1, interior: Here }), + fun: Fungible(34333299), + }, + weight_limit: Unlimited, + }, + ExportMessage { + network: Polkadot, + destination: X1(Parachain(1000)), + xcm: Xcm(vec![ + ReserveAssetDeposited(MultiAssets::from(vec![MultiAsset { + id: Concrete(MultiLocation { + parents: 2, + interior: X1(GlobalConsensus(Kusama)), + }), + fun: Fungible(1000000000000), + }])), + ClearOrigin, + BuyExecution { + fees: MultiAsset { + id: Concrete(MultiLocation { + parents: 2, + interior: X1(GlobalConsensus(Kusama)), + }), + fun: Fungible(1000000000000), + }, + weight_limit: Unlimited, + }, + DepositAsset { + assets: Wild(AllCounted(1)), + beneficiary: MultiLocation { + parents: 0, + interior: X1(xcm::latest::prelude::AccountId32 { + network: None, + id: [ + 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, + 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, + 109, 162, 125, + ], + }), + }, + }, + SetTopic([ + 116, 82, 194, 132, 171, 114, 217, 165, 23, 37, 161, 177, 165, 179, 247, 114, + 137, 101, 147, 70, 28, 157, 168, 32, 154, 63, 74, 228, 152, 180, 5, 63, + ]), + ]), + }, + RefundSurplus, + DepositAsset { + assets: Wild(All), + beneficiary: MultiLocation { parents: 1, interior: X1(Parachain(1000)) }, + }, + SetTopic([ + 36, 224, 250, 165, 82, 195, 67, 110, 160, 170, 140, 87, 217, 62, 201, 164, 42, 98, 219, + 157, 124, 105, 248, 25, 131, 218, 199, 36, 109, 173, 100, 122, + ]), + ]); + + // get weight + let weight = XcmConfig::Weigher::weight(&mut xcm); + assert_ok!(weight); + let weight = weight.unwrap(); + // check if sane + let max_expected = Runtime::BlockWeights::get().max_block / 10; + assert!( + weight.all_lte(max_expected), + "calculated weight: {:?}, max_expected: {:?}", + weight, + max_expected + ); + + // check fee, should not be 0 + let estimated_fee = WeightToFee::weight_to_fee(&weight); + assert!(estimated_fee > BalanceOf::::zero()); + + sp_tracing::try_init_simple(); + log::error!( + target: "bridges::estimate", + "Estimate fee: {:?} for `ExportMessage` for runtime: {:?}", + estimated_fee, + Runtime::Version::get(), + ); + + estimated_fee.into() +} + pub mod test_data { use super::*; use bp_header_chain::justification::GrandpaJustification;