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

Dynamic fees for bridges-v1 #2294

Merged
merged 33 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
74b48e2
impl backpressure in the XcmBlobHaulerAdapter
svyatonik Jul 14, 2023
65787da
LocalXcmQueueManager + more adapters
svyatonik Jul 21, 2023
3c98c24
OnMessageDelviered callback
svyatonik Jul 21, 2023
1fdac85
forbid mesage delivery transactions when the channel between target b…
svyatonik Jul 21, 2023
eea610a
pallet-xcm-bridge-hub-router
svyatonik Jul 24, 2023
c243013
removed commented code
svyatonik Jul 24, 2023
d9a0c2e
improvements and tests for palle-xcm-bridge-router
svyatonik Jul 27, 2023
d9515f7
use LocalXcmChannel in XcmBlobMessageDispatch
svyatonik Jul 27, 2023
084f551
new tests for logic changes in messages pallet
svyatonik Jul 27, 2023
d99420e
tests for LocalXcmQueueSuspender
svyatonik Jul 27, 2023
4c74171
tests for LocalXcmQueueMessageProcessor
svyatonik Jul 27, 2023
b75e64f
tests for new logic in the XcmBlobHaulerAdapter
svyatonik Jul 27, 2023
38cd8f3
fix other tests in the bridge-runtime-common
svyatonik Jul 27, 2023
9582435
extension_reject_call_when_dispatcher_is_inactive
svyatonik Jul 27, 2023
522bbc7
benchmarks for pallet-xcm-bridge-hub-router
svyatonik Jul 28, 2023
ed72ebe
get rid of redundant storage value
svyatonik Jul 28, 2023
c467911
add new pallet to verify-pallets-build.sh
svyatonik Jul 28, 2023
b26aa98
fixing spellcheck, clippy and rustdoc
svyatonik Jul 28, 2023
48f1ba0
trigger CI
svyatonik Jul 28, 2023
773f932
Revert "trigger CI"
svyatonik Jul 28, 2023
8d7a38a
change log target for xcm bridge router pallet
svyatonik Jul 31, 2023
7cc1470
Update modules/xcm-bridge-hub-router/src/lib.rs
svyatonik Aug 2, 2023
5d76f25
use saturated_len where possible
svyatonik Aug 2, 2023
c68467b
fmt
svyatonik Aug 2, 2023
e7cab6a
(Suggestion) Ability to externalize configuration for `ExporterFor` (…
bkontur Aug 3, 2023
dc3618a
Clippy
bkontur Aug 3, 2023
569a80f
Rename LocalXcmChannel to XcmChannelStatusProvider (#2319)
bkontur Aug 3, 2023
add9fb1
added/fixed some docs
svyatonik Aug 4, 2023
f822ebc
Dynamic fees v1: report congestion status to sending chain (#2318)
svyatonik Aug 4, 2023
ccf2f94
Merge remote-tracking branch 'origin/polkadot-staging' into dynamic-f…
bkontur Aug 10, 2023
8f86ec7
".git/.scripts/commands/fmt/fmt.sh"
Aug 10, 2023
91bf164
Added `XcmBridgeHubRouterCall::report_bridge_status` encodings for AH…
bkontur Aug 16, 2023
6dc0f60
Merge remote-tracking branch 'origin/polkadot-staging' into dynamic-f…
bkontur Aug 16, 2023
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
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
26 changes: 26 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"modules/parachains",
"modules/relayers",
"modules/shift-session-manager",
"modules/xcm-bridge-hub-router",
"primitives/beefy",
"primitives/chain-bridge-hub-cumulus",
"primitives/chain-bridge-hub-kusama",
Expand All @@ -37,6 +38,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 @@ -22,12 +22,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 @@ -89,6 +91,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 @@ -113,6 +116,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 @@ -139,6 +143,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",
]
40 changes: 38 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 @@ -544,6 +545,26 @@ 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 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 +603,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 +678,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 @@ -970,6 +995,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 @@ -1016,6 +1042,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 @@ -1126,6 +1156,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
10 changes: 5 additions & 5 deletions bin/millau/runtime/src/rialto_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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 _;
Expand All @@ -43,6 +43,8 @@ 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);
}

/// Message payload for Millau -> Rialto messages.
Expand All @@ -67,6 +69,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 @@ -125,15 +128,12 @@ pub struct ToRialtoXcmBlobHauler;
impl XcmBlobHauler for ToRialtoXcmBlobHauler {
type MessageSender = pallet_bridge_messages::Pallet<Runtime, WithRialtoMessagesInstance>;
type MessageSenderOrigin = RuntimeOrigin;
type SenderAndLane = RialtoSenderAndLane;

fn message_sender_origin() -> RuntimeOrigin {
pallet_xcm::Origin::from(MultiLocation::new(1, crate::xcm_config::UniversalLocation::get()))
.into()
}

fn xcm_lane() -> LaneId {
XCM_LANE
}
}

impl pallet_bridge_messages::WeightInfoExt for crate::weights::RialtoMessagesWeightInfo<Runtime> {
Expand Down
10 changes: 5 additions & 5 deletions bin/millau/runtime/src/rialto_parachain_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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 _;
Expand All @@ -45,6 +45,8 @@ 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);
}

/// Message payload for Millau -> RialtoParachain messages.
Expand All @@ -62,6 +64,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 @@ -126,15 +129,12 @@ impl XcmBlobHauler for ToRialtoParachainXcmBlobHauler {
type MessageSender =
pallet_bridge_messages::Pallet<Runtime, WithRialtoParachainMessagesInstance>;
type MessageSenderOrigin = RuntimeOrigin;
type SenderAndLane = RialtoParachainSenderAndLane;

fn message_sender_origin() -> RuntimeOrigin {
pallet_xcm::Origin::from(MultiLocation::new(1, crate::xcm_config::UniversalLocation::get()))
.into()
}

fn xcm_lane() -> LaneId {
XCM_LANE
}
}

impl pallet_bridge_messages::WeightInfoExt
Expand Down
19 changes: 19 additions & 0 deletions bin/millau/runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -235,6 +237,23 @@ 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 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::*;
Expand Down
10 changes: 5 additions & 5 deletions bin/rialto-parachain/runtime/src/millau_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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 xcm::latest::prelude::*;
Expand All @@ -45,6 +45,8 @@ 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-Millau bridge.
pub MullauSenderAndLane: SenderAndLane = SenderAndLane::new(Here.into(), XCM_LANE);
}

/// Message payload for RialtoParachain -> Millau messages.
Expand All @@ -62,6 +64,7 @@ pub type FromMillauMessageDispatch =
bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatch<
crate::OnRialtoParachainBlobDispatcher,
(),
(),
>;

/// Messages proof for Millau -> RialtoParachain messages.
Expand Down Expand Up @@ -125,14 +128,11 @@ pub struct ToMillauXcmBlobHauler;
impl XcmBlobHauler for ToMillauXcmBlobHauler {
type MessageSender = pallet_bridge_messages::Pallet<Runtime, WithMillauMessagesInstance>;
type MessageSenderOrigin = RuntimeOrigin;
type SenderAndLane = MullauSenderAndLane;

fn message_sender_origin() -> RuntimeOrigin {
pallet_xcm::Origin::from(MultiLocation::new(1, crate::UniversalLocation::get())).into()
}

fn xcm_lane() -> LaneId {
XCM_LANE
}
}

#[cfg(test)]
Expand Down
Loading