mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 05:11:02 +00:00
Dynamic fees for bridges-v1 (#2294)
* impl backpressure in the XcmBlobHaulerAdapter * LocalXcmQueueManager + more adapters * OnMessageDelviered callback * forbid mesage delivery transactions when the channel between target bridge hub and target asset hub is suspended * pallet-xcm-bridge-hub-router * removed commented code * improvements and tests for palle-xcm-bridge-router * use LocalXcmChannel in XcmBlobMessageDispatch * new tests for logic changes in messages pallet * tests for LocalXcmQueueSuspender * tests for LocalXcmQueueMessageProcessor * tests for new logic in the XcmBlobHaulerAdapter * fix other tests in the bridge-runtime-common * extension_reject_call_when_dispatcher_is_inactive * benchmarks for pallet-xcm-bridge-hub-router * get rid of redundant storage value * add new pallet to verify-pallets-build.sh * fixing spellcheck, clippy and rustdoc * trigger CI * Revert "trigger CI" This reverts commit 48f1ba032334e3c6d8470436483736988aa060ac. * change log target for xcm bridge router pallet * Update modules/xcm-bridge-hub-router/src/lib.rs Co-authored-by: Branislav Kontur <bkontur@gmail.com> * use saturated_len where possible * fmt * (Suggestion) Ability to externalize configuration for `ExporterFor` (#2313) * Ability to externalize configuration for `ExporterFor` (Replaced `BridgedNetworkId/SiblingBridgeHubLocation` with `Bridges: ExporterFor`) * Fix millau * Compile fix * Return back `BridgedNetworkId` but as optional filter * Replaced `BaseFee` with fees from inner `Bridges: ExporterFor` * typo * Clippy * Rename LocalXcmChannel to XcmChannelStatusProvider (#2319) * Rename LocalXcmChannel to XcmChannelStatusProvider * fmt * added/fixed some docs * Dynamic fees v1: report congestion status to sending chain (#2318) * report congestion status: changes at the sending chain * OnMessagesDelivered is back * report congestion status: changes at the bridge hub * moer logging * fix? benchmarks * spelling * tests for XcmBlobHaulerAdapter and LocalXcmQueueManager * tests for messages pallet * fix typo * rustdoc * Update modules/messages/src/lib.rs * apply review suggestions * ".git/.scripts/commands/fmt/fmt.sh" * Added `XcmBridgeHubRouterCall::report_bridge_status` encodings for AHK/P (#2350) * Added `XcmBridgeHubRouterCall::report_bridge_status` encodings for AHK/P * Spellcheck * Added const for `XcmBridgeHubRouterTransactCallMaxWeight` * Cargo.lock * Introduced base delivery fee constants * Congestion messages as Optional to turn on/off `supports_congestion_detection` * Spellcheck * Ability to externalize dest for benchmarks * Ability to externalize dest for benchmarks --------- Co-authored-by: Branislav Kontur <bkontur@gmail.com> Co-authored-by: command-bot <>
This commit is contained in:
committed by
Bastian Köcher
parent
dc8aa5df7d
commit
31a6cbeafb
@@ -23,12 +23,14 @@ bp-rialto = { path = "../../../primitives/chain-rialto", default-features = fals
|
||||
bp-rialto-parachain = { path = "../../../primitives/chain-rialto-parachain", default-features = false }
|
||||
bp-runtime = { path = "../../../primitives/runtime", default-features = false }
|
||||
bp-westend = { path = "../../../primitives/chain-westend", default-features = false }
|
||||
bp-xcm-bridge-hub-router = { path = "../../../primitives/xcm-bridge-hub-router", default-features = false }
|
||||
bridge-runtime-common = { path = "../../runtime-common", default-features = false }
|
||||
pallet-bridge-grandpa = { path = "../../../modules/grandpa", default-features = false }
|
||||
pallet-bridge-messages = { path = "../../../modules/messages", default-features = false }
|
||||
pallet-bridge-parachains = { path = "../../../modules/parachains", default-features = false }
|
||||
pallet-bridge-relayers = { path = "../../../modules/relayers", default-features = false }
|
||||
pallet-shift-session-manager = { path = "../../../modules/shift-session-manager", default-features = false }
|
||||
pallet-xcm-bridge-hub-router = { path = "../../../modules/xcm-bridge-hub-router", default-features = false }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
@@ -90,6 +92,7 @@ std = [
|
||||
"bp-rialto-parachain/std",
|
||||
"bp-runtime/std",
|
||||
"bp-westend/std",
|
||||
"bp-xcm-bridge-hub-router/std",
|
||||
"bridge-runtime-common/std",
|
||||
"codec/std",
|
||||
"frame-executive/std",
|
||||
@@ -114,6 +117,7 @@ std = [
|
||||
"pallet-transaction-payment/std",
|
||||
"pallet-utility/std",
|
||||
"pallet-xcm/std",
|
||||
"pallet-xcm-bridge-hub-router/std",
|
||||
"scale-info/std",
|
||||
"sp-api/std",
|
||||
"sp-block-builder/std",
|
||||
@@ -140,6 +144,7 @@ runtime-benchmarks = [
|
||||
"pallet-bridge-parachains/runtime-benchmarks",
|
||||
"pallet-bridge-relayers/runtime-benchmarks",
|
||||
"pallet-xcm/runtime-benchmarks",
|
||||
"pallet-xcm-bridge-hub-router/runtime-benchmarks",
|
||||
"sp-runtime/runtime-benchmarks",
|
||||
"xcm-builder/runtime-benchmarks",
|
||||
]
|
||||
|
||||
@@ -55,6 +55,7 @@ use sp_std::prelude::*;
|
||||
#[cfg(feature = "std")]
|
||||
use sp_version::NativeVersion;
|
||||
use sp_version::RuntimeVersion;
|
||||
use xcm_builder::NetworkExportTable;
|
||||
|
||||
// to be able to use Millau runtime in `bridge-runtime-common` tests
|
||||
pub use bridge_runtime_common;
|
||||
@@ -65,8 +66,8 @@ pub use frame_support::{
|
||||
dispatch::DispatchClass,
|
||||
parameter_types,
|
||||
traits::{
|
||||
ConstBool, ConstU32, ConstU64, ConstU8, Currency, ExistenceRequirement, Imbalance,
|
||||
KeyOwnerProofSystem,
|
||||
ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Currency, ExistenceRequirement,
|
||||
Imbalance, KeyOwnerProofSystem,
|
||||
},
|
||||
weights::{
|
||||
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, IdentityFee, RuntimeDbWeight,
|
||||
@@ -464,6 +465,7 @@ impl pallet_bridge_messages::Config<WithRialtoMessagesInstance> for Runtime {
|
||||
WithRialtoMessagesInstance,
|
||||
frame_support::traits::ConstU64<100_000>,
|
||||
>;
|
||||
type OnMessagesDelivered = ();
|
||||
|
||||
type SourceHeaderChain = crate::rialto_messages::RialtoAsSourceHeaderChain;
|
||||
type MessageDispatch = crate::rialto_messages::FromRialtoMessageDispatch;
|
||||
@@ -495,6 +497,7 @@ impl pallet_bridge_messages::Config<WithRialtoParachainMessagesInstance> for Run
|
||||
WithRialtoParachainMessagesInstance,
|
||||
frame_support::traits::ConstU64<100_000>,
|
||||
>;
|
||||
type OnMessagesDelivered = ();
|
||||
|
||||
type SourceHeaderChain = crate::rialto_parachain_messages::RialtoParachainAsSourceHeaderChain;
|
||||
type MessageDispatch = crate::rialto_parachain_messages::FromRialtoParachainMessageDispatch;
|
||||
@@ -544,6 +547,27 @@ impl pallet_utility::Config for Runtime {
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
// this config is totally incorrect - the pallet is not actually used at this runtime. We need
|
||||
// it only to be able to run benchmarks and make required traits (and default weights for tests).
|
||||
parameter_types! {
|
||||
pub BridgeTable: Vec<(xcm::prelude::NetworkId, xcm::prelude::MultiLocation, Option<xcm::prelude::MultiAsset>)>
|
||||
= vec![(xcm_config::RialtoNetwork::get(), xcm_config::TokenLocation::get(), Some((xcm_config::TokenAssetId::get(), 1_000_000_000_u128).into()))];
|
||||
}
|
||||
impl pallet_xcm_bridge_hub_router::Config for Runtime {
|
||||
type WeightInfo = ();
|
||||
|
||||
type UniversalLocation = xcm_config::UniversalLocation;
|
||||
type BridgedNetworkId = xcm_config::RialtoNetwork;
|
||||
type Bridges = NetworkExportTable<BridgeTable>;
|
||||
|
||||
type BridgeHubOrigin = frame_system::EnsureRoot<AccountId>;
|
||||
type ToBridgeHubSender = xcm_config::XcmRouter;
|
||||
type WithBridgeHubChannel = xcm_config::EmulatedSiblingXcmpChannel;
|
||||
|
||||
type ByteFee = ConstU128<1_000>;
|
||||
type FeeAsset = xcm_config::TokenAssetId;
|
||||
}
|
||||
|
||||
construct_runtime!(
|
||||
pub enum Runtime {
|
||||
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
|
||||
@@ -582,6 +606,9 @@ construct_runtime!(
|
||||
|
||||
// Pallet for sending XCM.
|
||||
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config<T>} = 99,
|
||||
|
||||
// Pallets that are not actually used here (yet?), but we need to run benchmarks on it.
|
||||
XcmBridgeHubRouter: pallet_xcm_bridge_hub_router::{Pallet, Storage} = 200,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -654,6 +681,7 @@ mod benches {
|
||||
[pallet_bridge_grandpa, BridgeRialtoGrandpa]
|
||||
[pallet_bridge_parachains, ParachainsBench::<Runtime, WithRialtoParachainsInstance>]
|
||||
[pallet_bridge_relayers, RelayersBench::<Runtime>]
|
||||
[pallet_xcm_bridge_hub_router, XcmBridgeHubRouterBench::<Runtime>]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -980,6 +1008,7 @@ impl_runtime_apis! {
|
||||
use pallet_bridge_messages::benchmarking::Pallet as MessagesBench;
|
||||
use pallet_bridge_parachains::benchmarking::Pallet as ParachainsBench;
|
||||
use pallet_bridge_relayers::benchmarking::Pallet as RelayersBench;
|
||||
use pallet_xcm_bridge_hub_router::benchmarking::Pallet as XcmBridgeHubRouterBench;
|
||||
|
||||
let mut list = Vec::<BenchmarkList>::new();
|
||||
list_benchmarks!(list, extra);
|
||||
@@ -1026,6 +1055,10 @@ impl_runtime_apis! {
|
||||
Pallet as RelayersBench,
|
||||
Config as RelayersConfig,
|
||||
};
|
||||
use pallet_xcm_bridge_hub_router::benchmarking::{
|
||||
Pallet as XcmBridgeHubRouterBench,
|
||||
Config as XcmBridgeHubRouterConfig,
|
||||
};
|
||||
use rialto_messages::WithRialtoMessageBridge;
|
||||
use rialto_parachain_messages::WithRialtoParachainMessageBridge;
|
||||
|
||||
@@ -1136,6 +1169,12 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
impl XcmBridgeHubRouterConfig<()> for Runtime {
|
||||
fn make_congested() {
|
||||
xcm_config::EmulatedSiblingXcmpChannel::make_congested()
|
||||
}
|
||||
}
|
||||
|
||||
let mut batches = Vec::<BenchmarkBatch>::new();
|
||||
let params = (&config, &whitelist);
|
||||
|
||||
|
||||
@@ -23,10 +23,11 @@ use bridge_runtime_common::{
|
||||
messages::{
|
||||
self, source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, MessageBridge,
|
||||
},
|
||||
messages_xcm_extension::{XcmBlobHauler, XcmBlobHaulerAdapter},
|
||||
messages_xcm_extension::{SenderAndLane, XcmBlobHauler, XcmBlobHaulerAdapter},
|
||||
};
|
||||
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
||||
use pallet_bridge_relayers::WeightInfoExt as _;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_builder::HaulBlobExporter;
|
||||
|
||||
/// Default lane that is used to send messages to Rialto.
|
||||
@@ -42,6 +43,11 @@ parameter_types! {
|
||||
/// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
|
||||
/// (it is prepended with `UniversalOrigin` instruction).
|
||||
pub const WeightCredit: Weight = BASE_XCM_WEIGHT_TWICE;
|
||||
/// Lane used by the with-Rialto bridge.
|
||||
pub RialtoSenderAndLane: SenderAndLane = SenderAndLane::new(Here.into(), XCM_LANE);
|
||||
|
||||
/// Dummy message used in configuration.
|
||||
pub DummyXcmMessage: Xcm<()> = Xcm::new();
|
||||
}
|
||||
|
||||
/// Message payload for Millau -> Rialto messages.
|
||||
@@ -66,6 +72,7 @@ pub type FromRialtoMessageDispatch =
|
||||
bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatch<
|
||||
crate::xcm_config::OnMillauBlobDispatcher,
|
||||
(),
|
||||
(),
|
||||
>;
|
||||
|
||||
/// Maximal outbound payload size of Millau -> Rialto messages.
|
||||
@@ -122,11 +129,13 @@ pub type ToRialtoBlobExporter = HaulBlobExporter<
|
||||
pub struct ToRialtoXcmBlobHauler;
|
||||
|
||||
impl XcmBlobHauler for ToRialtoXcmBlobHauler {
|
||||
type MessageSender = pallet_bridge_messages::Pallet<Runtime, WithRialtoMessagesInstance>;
|
||||
type Runtime = Runtime;
|
||||
type MessagesInstance = WithRialtoMessagesInstance;
|
||||
type SenderAndLane = RialtoSenderAndLane;
|
||||
|
||||
fn xcm_lane() -> LaneId {
|
||||
XCM_LANE
|
||||
}
|
||||
type ToSourceChainSender = crate::xcm_config::XcmRouter;
|
||||
type CongestedMessage = DummyXcmMessage;
|
||||
type UncongestedMessage = DummyXcmMessage;
|
||||
}
|
||||
|
||||
impl pallet_bridge_messages::WeightInfoExt for crate::weights::RialtoMessagesWeightInfo<Runtime> {
|
||||
|
||||
@@ -25,10 +25,11 @@ use bridge_runtime_common::{
|
||||
messages::{
|
||||
self, source::TargetHeaderChainAdapter, target::SourceHeaderChainAdapter, MessageBridge,
|
||||
},
|
||||
messages_xcm_extension::{XcmBlobHauler, XcmBlobHaulerAdapter},
|
||||
messages_xcm_extension::{SenderAndLane, XcmBlobHauler, XcmBlobHaulerAdapter},
|
||||
};
|
||||
use frame_support::{parameter_types, weights::Weight, RuntimeDebug};
|
||||
use pallet_bridge_relayers::WeightInfoExt as _;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_builder::HaulBlobExporter;
|
||||
|
||||
/// Default lane that is used to send messages to Rialto parachain.
|
||||
@@ -44,6 +45,11 @@ parameter_types! {
|
||||
/// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
|
||||
/// (it is prepended with `UniversalOrigin` instruction).
|
||||
pub const WeightCredit: Weight = BASE_XCM_WEIGHT_TWICE;
|
||||
/// Lane used by the with-RialtoParachain bridge.
|
||||
pub RialtoParachainSenderAndLane: SenderAndLane = SenderAndLane::new(Here.into(), XCM_LANE);
|
||||
|
||||
/// Dummy message used in configuration.
|
||||
pub DummyXcmMessage: Xcm<()> = Xcm::new();
|
||||
}
|
||||
|
||||
/// Message payload for Millau -> RialtoParachain messages.
|
||||
@@ -61,6 +67,7 @@ pub type FromRialtoParachainMessageDispatch =
|
||||
bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatch<
|
||||
crate::xcm_config::OnMillauBlobDispatcher,
|
||||
(),
|
||||
(),
|
||||
>;
|
||||
|
||||
/// Maximal outbound payload size of Millau -> RialtoParachain messages.
|
||||
@@ -122,12 +129,13 @@ pub type ToRialtoParachainBlobExporter = HaulBlobExporter<
|
||||
pub struct ToRialtoParachainXcmBlobHauler;
|
||||
|
||||
impl XcmBlobHauler for ToRialtoParachainXcmBlobHauler {
|
||||
type MessageSender =
|
||||
pallet_bridge_messages::Pallet<Runtime, WithRialtoParachainMessagesInstance>;
|
||||
type Runtime = Runtime;
|
||||
type MessagesInstance = WithRialtoParachainMessagesInstance;
|
||||
type SenderAndLane = RialtoParachainSenderAndLane;
|
||||
|
||||
fn xcm_lane() -> LaneId {
|
||||
XCM_LANE
|
||||
}
|
||||
type ToSourceChainSender = crate::xcm_config::XcmRouter;
|
||||
type CongestedMessage = DummyXcmMessage;
|
||||
type UncongestedMessage = DummyXcmMessage;
|
||||
}
|
||||
|
||||
impl pallet_bridge_messages::WeightInfoExt
|
||||
|
||||
@@ -42,6 +42,8 @@ parameter_types! {
|
||||
/// chain, we make it synonymous with it and thus it is the `Here` location, which means "equivalent to
|
||||
/// the context".
|
||||
pub const TokenLocation: MultiLocation = Here.into_location();
|
||||
/// Token asset identifier.
|
||||
pub TokenAssetId: AssetId = TokenLocation::get().into();
|
||||
/// The Millau network ID.
|
||||
pub const ThisNetwork: NetworkId = CustomNetworkId::Millau.as_network_id();
|
||||
/// The Rialto network ID.
|
||||
@@ -98,7 +100,7 @@ parameter_types! {
|
||||
}
|
||||
|
||||
/// The XCM router. We are not sending messages to sibling/parent/child chains here.
|
||||
pub type XcmRouter = ();
|
||||
pub type XcmRouter = EmulatedSiblingXcmpChannel;
|
||||
|
||||
/// The barriers one of which must be passed for an XCM message to be executed.
|
||||
pub type Barrier = (
|
||||
@@ -235,6 +237,38 @@ impl ExportXcm for ToRialtoOrRialtoParachainSwitchExporter {
|
||||
}
|
||||
}
|
||||
|
||||
/// Emulating XCMP channel with sibling chain. We don't have required infra here, at Millau,
|
||||
/// so we have to provide at least something to be able to run benchmarks.
|
||||
pub struct EmulatedSiblingXcmpChannel;
|
||||
|
||||
impl SendXcm for EmulatedSiblingXcmpChannel {
|
||||
type Ticket = ();
|
||||
|
||||
fn validate(
|
||||
_destination: &mut Option<MultiLocation>,
|
||||
_message: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<Self::Ticket> {
|
||||
Ok(((), Default::default()))
|
||||
}
|
||||
|
||||
fn deliver(_ticket: Self::Ticket) -> Result<XcmHash, SendError> {
|
||||
Ok(XcmHash::default())
|
||||
}
|
||||
}
|
||||
|
||||
impl EmulatedSiblingXcmpChannel {
|
||||
/// Start emulating congested channel.
|
||||
pub fn make_congested() {
|
||||
frame_support::storage::unhashed::put(b"EmulatedSiblingXcmpChannel.Congested", &true);
|
||||
}
|
||||
}
|
||||
|
||||
impl bp_xcm_bridge_hub_router::XcmChannelStatusProvider for EmulatedSiblingXcmpChannel {
|
||||
fn is_congested() -> bool {
|
||||
frame_support::storage::unhashed::get_or_default(b"EmulatedSiblingXcmpChannel.Congested")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -357,7 +391,7 @@ mod tests {
|
||||
let dispatch_result = FromRialtoMessageDispatch::dispatch(incoming_message);
|
||||
assert!(matches!(
|
||||
dispatch_result.dispatch_level_result,
|
||||
XcmBlobMessageDispatchResult::NotDispatched(_),
|
||||
XcmBlobMessageDispatchResult::Dispatched,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -370,7 +404,7 @@ mod tests {
|
||||
let dispatch_result = FromRialtoMessageDispatch::dispatch(incoming_message);
|
||||
assert!(matches!(
|
||||
dispatch_result.dispatch_level_result,
|
||||
XcmBlobMessageDispatchResult::NotDispatched(_),
|
||||
XcmBlobMessageDispatchResult::Dispatched,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user