Skip to content

Commit

Permalink
Dynamic fees for bridges-v1 (#2294)
Browse files Browse the repository at this point in the history
* 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 <>
  • Loading branch information
svyatonik and bkontur authored Aug 16, 2023
1 parent b1c51f7 commit 277f0d5
Show file tree
Hide file tree
Showing 36 changed files with 2,106 additions and 71 deletions.
3 changes: 3 additions & 0 deletions .config/lingua.dic
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Best/MS
BlockId
BlockNumber
BridgeStorage
AssetHub
AssetHubKusama
AssetHubPolkadot
BridgeHub
BridgeHubRococo
BridgeHubWococo
Expand Down
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ benchmarks-test:
- time cargo run --release -p millau-bridge-node --features=runtime-benchmarks -- benchmark pallet --chain=dev --steps=2 --repeat=1 --pallet=pallet_bridge_grandpa --extrinsic=* --execution=wasm --wasm-execution=Compiled --heap-pages=4096
- time cargo run --release -p millau-bridge-node --features=runtime-benchmarks -- benchmark pallet --chain=dev --steps=2 --repeat=1 --pallet=pallet_bridge_parachains --extrinsic=* --execution=wasm --wasm-execution=Compiled --heap-pages=4096
- time cargo run --release -p millau-bridge-node --features=runtime-benchmarks -- benchmark pallet --chain=dev --steps=2 --repeat=1 --pallet=pallet_bridge_relayers --extrinsic=* --execution=wasm --wasm-execution=Compiled --heap-pages=4096
- time cargo run --release -p millau-bridge-node --features=runtime-benchmarks -- benchmark pallet --chain=dev --steps=2 --repeat=1 --pallet=pallet_xcm_bridge_hub_router --extrinsic=* --execution=wasm --wasm-execution=Compiled --heap-pages=4096
# we may live with failing benchmarks, it is just a signal for us
allow_failure: true

Expand Down
52 changes: 52 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ members = [
"modules/parachains",
"modules/relayers",
"modules/shift-session-manager",
"modules/xcm-bridge-hub-router",
"primitives/beefy",
"primitives/chain-asset-hub-kusama",
"primitives/chain-asset-hub-polkadot",
"primitives/chain-bridge-hub-cumulus",
"primitives/chain-bridge-hub-kusama",
"primitives/chain-bridge-hub-polkadot",
Expand All @@ -37,6 +40,7 @@ members = [
"primitives/relayers",
"primitives/runtime",
"primitives/test-utils",
"primitives/xcm-bridge-hub-router",
"relays/bin-substrate",
"relays/client-bridge-hub-kusama",
"relays/client-bridge-hub-polkadot",
Expand Down
5 changes: 5 additions & 0 deletions bin/millau/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
]
43 changes: 41 additions & 2 deletions bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>},
Expand Down Expand Up @@ -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,
}
);

Expand Down Expand Up @@ -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>]
);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
19 changes: 14 additions & 5 deletions bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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> {
Expand Down
20 changes: 14 additions & 6 deletions bin/millau/runtime/src/rialto_parachain_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 277f0d5

Please sign in to comment.