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

Bridges - revert-back and improve congestion #6231

Open
wants to merge 82 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
ad0931c
Nits
bkontur Oct 25, 2024
efce0e7
Remove internal `ViaBridgeHubExporter/SovereignPaidRemoteExporter` an…
bkontur Oct 25, 2024
28a19f8
doc
bkontur Oct 25, 2024
725f667
".git/.scripts/commands/fmt/fmt.sh"
Oct 25, 2024
63a1fd6
Update from bkontur running command 'prdoc --audience runtime_dev --b…
actions-user Oct 25, 2024
a9db6f5
Simplification: Merge `bridge_owner_account` / `deposit` to optional …
bkontur Oct 25, 2024
382dbe8
Update prdoc/pr_6231.prdoc
bkontur Oct 26, 2024
660b3fa
Add tests that `pallet-xcm-bridge-hub-router` can work locally with `…
bkontur Oct 26, 2024
3b36975
Fix testnet runtimes
bkontur Oct 26, 2024
b77d3ac
".git/.scripts/commands/fmt/fmt.sh"
Oct 26, 2024
abd2f00
nit
bkontur Oct 26, 2024
095d124
Extract dynamic fees calculation as separate feature
bkontur Oct 28, 2024
459228a
".git/.scripts/commands/fmt/fmt.sh"
Oct 28, 2024
3f32d75
We don't need `ExporterFor/Bridges` for `pallet-xcm-bridge-hub-router…
bkontur Oct 28, 2024
cb71f3e
Implement congestion and dynamic fees for logical bridges - part1
bkontur Oct 31, 2024
24626fd
Nits
bkontur Nov 2, 2024
fa2f8c7
Report congestion and logical bridges/channel with tests
bkontur Nov 4, 2024
0505440
Add `BlobDispatcherWithChannelStatus` adapter
bkontur Nov 5, 2024
a56c546
Cleanup primitives/consts
bkontur Nov 5, 2024
4334b70
Adapt testnet runtimes to latest congestion changes
bkontur Nov 5, 2024
d4d0b11
".git/.scripts/commands/fmt/fmt.sh"
Nov 5, 2024
5e28b0d
Add `maybe_notify` callback for congestion
bkontur Nov 6, 2024
2fc4cba
Added `update_notification_receiver` extrinsic
bkontur Nov 6, 2024
7e5dd3f
Removed `require_weight_at_most` for xcm::v5
bkontur Nov 7, 2024
73e404a
Benchmarks for `pallet-xcm-bridge-hub-router`
bkontur Nov 7, 2024
5eefeec
Update from bkontur running command 'fmt'
actions-user Nov 7, 2024
4c1129c
Fix benchmarks
bkontur Nov 7, 2024
3b8f8db
Fix benchmarks for BH
bkontur Nov 7, 2024
b557388
Update from bkontur running command 'fmt'
actions-user Nov 7, 2024
ca045ea
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 7, 2024
78afc1c
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 7, 2024
4d16cc5
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 7, 2024
c031d48
Fixed benchmarks
bkontur Nov 7, 2024
28fc081
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Nov 7, 2024
87098db
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Nov 7, 2024
806f096
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 7, 2024
b5b25ce
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 7, 2024
31a9670
Update from bkontur running command 'fmt'
actions-user Nov 8, 2024
48f9f00
Adjust const
bkontur Nov 8, 2024
39eeb89
Add benchmarks for pallet-xcm-bridge-hub
bkontur Nov 8, 2024
7adcefd
Update from bkontur running command 'fmt'
actions-user Nov 8, 2024
26bb7a9
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 9, 2024
4602edb
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 9, 2024
be876b2
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Nov 9, 2024
178b76e
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 9, 2024
54adf00
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 9, 2024
ef2321a
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 9, 2024
ea8d9dc
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=br…
Nov 9, 2024
15f4e69
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
Nov 9, 2024
6d415be
clippy + weights
bkontur Nov 9, 2024
3e32dcf
Adds ability to stop `exporting` more messages (a.k.a dropping).
bkontur Nov 11, 2024
fbcacb0
Update from bkontur running command 'fmt'
actions-user Nov 11, 2024
9e11db5
Fix
bkontur Nov 11, 2024
6513057
Fix
bkontur Nov 11, 2024
31045aa
Update from bkontur running command 'fmt'
actions-user Nov 11, 2024
8a7eb9a
Forgotten prdoc
bkontur Nov 11, 2024
15761c1
Merge branch 'master' into bko-bridges-congestion
bkontur Nov 11, 2024
cd92d5e
Update bridges/modules/xcm-bridge-hub/src/benchmarking.rs
bkontur Nov 14, 2024
4b6deb9
Update bridges/modules/xcm-bridge-hub-router/src/lib.rs
bkontur Nov 14, 2024
ac092d3
Update bridges/modules/xcm-bridge-hub-router/src/impls.rs
bkontur Nov 14, 2024
393cded
Update bridges/modules/xcm-bridge-hub-router/src/impls.rs
bkontur Nov 14, 2024
1bcbbdf
Merge remote-tracking branch 'origin/master' into bko-bridges-congestion
bkontur Nov 14, 2024
bdb8c8a
Removed `sp_tracing::try_init_simple`
bkontur Nov 14, 2024
b8efb0b
Update bridges/modules/xcm-bridge-hub-router/src/lib.rs
bkontur Nov 14, 2024
162c1f6
Link types - review comment
bkontur Nov 14, 2024
b8d2742
PR review - fees -> fee
bkontur Nov 14, 2024
ecf3499
PR review - change `on_initialize` to `on_idle`
bkontur Nov 14, 2024
f643ec7
Update from bkontur running command 'fmt'
actions-user Nov 14, 2024
8518de3
PR review - updated docs
bkontur Nov 14, 2024
8a082c1
clippy
bkontur Nov 15, 2024
0ccfef2
Merge remote-tracking branch 'origin/master' into bko-bridges-congestion
bkontur Nov 15, 2024
465db5f
Update from bkontur running command 'fmt'
actions-user Nov 15, 2024
37974be
Merge branch 'master' into bko-bridges-congestion
bkontur Nov 16, 2024
416e2e0
PR review
bkontur Nov 19, 2024
9f66e49
Merge remote-tracking branch 'origin/master' into bko-bridges-congestion
bkontur Nov 19, 2024
15ef0a4
PR review - removed brackets
bkontur Nov 19, 2024
296476e
PR review
bkontur Nov 19, 2024
d69c22b
Merge remote-tracking branch 'origin/master' into bko-bridges-congestion
bkontur Nov 20, 2024
02285ac
PR review - renamed report_bridge_status to update_bridge_status
bkontur Nov 20, 2024
f18e230
Merge remote-tracking branch 'origin/master' into bko-bridges-congestion
bkontur Nov 20, 2024
a5eb1c3
Update from bkontur running command 'fmt'
actions-user Nov 21, 2024
4c1c315
Merge branch 'master' into bko-bridges-congestion
bkontur Nov 21, 2024
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
16 changes: 3 additions & 13 deletions Cargo.lock

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

15 changes: 1 addition & 14 deletions bridges/chains/chain-asset-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,7 @@ exclude-from-umbrella = true
workspace = true

[dependencies]
codec = { workspace = true }
scale-info = { features = ["derive"], workspace = true }

# Substrate Dependencies
frame-support = { workspace = true }

# Bridge Dependencies
bp-xcm-bridge-hub-router = { workspace = true }

[features]
default = ["std"]
std = [
"bp-xcm-bridge-hub-router/std",
"codec/std",
"frame-support/std",
"scale-info/std",
]
std = []
26 changes: 0 additions & 26 deletions bridges/chains/chain-asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,5 @@

#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Decode, Encode};
use scale_info::TypeInfo;

pub use bp_xcm_bridge_hub_router::XcmBridgeHubRouterCall;

/// `AssetHubRococo` Runtime `Call` enum.
///
/// The enum represents a subset of possible `Call`s we can send to `AssetHubRococo` chain.
/// Ideally this code would be auto-generated from metadata, because we want to
/// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s.
///
/// All entries here (like pretty much in the entire file) must be kept in sync with
/// `AssetHubRococo` `construct_runtime`, so that we maintain SCALE-compatibility.
#[allow(clippy::large_enum_variant)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub enum Call {
/// `ToWestendXcmRouter` bridge pallet.
#[codec(index = 45)]
ToWestendXcmRouter(XcmBridgeHubRouterCall),
}

frame_support::parameter_types! {
/// Some sane weight to execute `xcm::Transact(pallet-xcm-bridge-hub-router::Call::report_bridge_status)`.
pub const XcmBridgeHubRouterTransactCallMaxWeight: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(200_000_000, 6144);
}

/// Identifier of AssetHubRococo in the Rococo relay chain.
pub const ASSET_HUB_ROCOCO_PARACHAIN_ID: u32 = 1000;
15 changes: 1 addition & 14 deletions bridges/chains/chain-asset-hub-westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,7 @@ exclude-from-umbrella = true
workspace = true

[dependencies]
codec = { workspace = true }
scale-info = { features = ["derive"], workspace = true }

# Substrate Dependencies
frame-support = { workspace = true }

# Bridge Dependencies
bp-xcm-bridge-hub-router = { workspace = true }

[features]
default = ["std"]
std = [
"bp-xcm-bridge-hub-router/std",
"codec/std",
"frame-support/std",
"scale-info/std",
]
std = []
26 changes: 0 additions & 26 deletions bridges/chains/chain-asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,5 @@

#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Decode, Encode};
use scale_info::TypeInfo;

pub use bp_xcm_bridge_hub_router::XcmBridgeHubRouterCall;

/// `AssetHubWestend` Runtime `Call` enum.
///
/// The enum represents a subset of possible `Call`s we can send to `AssetHubWestend` chain.
/// Ideally this code would be auto-generated from metadata, because we want to
/// avoid depending directly on the ENTIRE runtime just to get the encoding of `Dispatchable`s.
///
/// All entries here (like pretty much in the entire file) must be kept in sync with
/// `AssetHubWestend` `construct_runtime`, so that we maintain SCALE-compatibility.
#[allow(clippy::large_enum_variant)]
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
pub enum Call {
/// `ToRococoXcmRouter` bridge pallet.
#[codec(index = 34)]
ToRococoXcmRouter(XcmBridgeHubRouterCall),
}

frame_support::parameter_types! {
/// Some sane weight to execute `xcm::Transact(pallet-xcm-bridge-hub-router::Call::report_bridge_status)`.
pub const XcmBridgeHubRouterTransactCallMaxWeight: frame_support::weights::Weight = frame_support::weights::Weight::from_parts(200_000_000, 6144);
}

/// Identifier of AssetHubWestend in the Westend relay chain.
pub const ASSET_HUB_WESTEND_PARACHAIN_ID: u32 = 1000;
2 changes: 1 addition & 1 deletion bridges/chains/chain-bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ frame_support::parameter_types! {
/// The XCM fee that is paid for executing XCM program (with `ExportMessage` instruction) at the Rococo
/// BridgeHub.
/// (initially was calculated by test `BridgeHubRococo::can_calculate_weight_for_paid_export_message_with_reserve_transfer` + `33%`)
pub const BridgeHubRococoBaseXcmFeeInRocs: u128 = 57_145_832;
pub const BridgeHubRococoBaseXcmFeeInRocs: u128 = 57_325_000;

/// Transaction fee that is paid at the Rococo BridgeHub for delivering single inbound message.
/// (initially was calculated by test `BridgeHubRococo::can_calculate_fee_for_standalone_message_delivery_transaction` + `33%`)
Expand Down
2 changes: 1 addition & 1 deletion bridges/chains/chain-bridge-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ frame_support::parameter_types! {
/// The XCM fee that is paid for executing XCM program (with `ExportMessage` instruction) at the Westend
/// BridgeHub.
/// (initially was calculated by test `BridgeHubWestend::can_calculate_weight_for_paid_export_message_with_reserve_transfer` + `33%`)
pub const BridgeHubWestendBaseXcmFeeInWnds: u128 = 18_191_740_000;
pub const BridgeHubWestendBaseXcmFeeInWnds: u128 = 18_248_930_000;

/// Transaction fee that is paid at the Westend BridgeHub for delivering single inbound message.
/// (initially was calculated by test `BridgeHubWestend::can_calculate_fee_for_standalone_message_delivery_transaction` + `33%`)
Expand Down
2 changes: 0 additions & 2 deletions bridges/modules/relayers/src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ mod tests {
use bp_runtime::{BasicOperatingMode, HeaderId, Parachain};
use bp_test_utils::{make_default_justification, test_keyring, TEST_GRANDPA_SET_ID};
use frame_support::{
__private::sp_tracing,
assert_storage_noop, parameter_types,
traits::{fungible::Mutate, ReservableCurrency},
weights::Weight,
Expand Down Expand Up @@ -1127,7 +1126,6 @@ mod tests {
Option<PreDispatchData<ThisChainAccountId, BridgedChainBlockNumber, TestLaneIdType>>,
TransactionValidityError,
> {
sp_tracing::try_init_simple();
let extension: TestExtension = BridgeRelayersTransactionExtension(PhantomData);
extension
.validate_and_prepare(
Expand Down
2 changes: 2 additions & 0 deletions bridges/modules/xcm-bridge-hub-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ scale-info = { features = ["bit-vec", "derive", "serde"], workspace = true }

# Bridge dependencies
bp-xcm-bridge-hub-router = { workspace = true }
bp-xcm-bridge-hub = { workspace = true }

# Substrate Dependencies
frame-benchmarking = { optional = true, workspace = true }
Expand All @@ -38,6 +39,7 @@ sp-std = { workspace = true, default-features = true }
default = ["std"]
std = [
"bp-xcm-bridge-hub-router/std",
"bp-xcm-bridge-hub/std",
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
Expand Down
104 changes: 78 additions & 26 deletions bridges/modules/xcm-bridge-hub-router/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,95 @@

#![cfg(feature = "runtime-benchmarks")]

use crate::{DeliveryFeeFactor, MINIMAL_DELIVERY_FEE_FACTOR};
use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError};
use frame_support::traits::{Get, Hooks};
use sp_runtime::traits::Zero;
use crate::{BridgeState, Bridges, Call, ResolveBridgeId, MINIMAL_DELIVERY_FEE_FACTOR};
use frame_benchmarking::v2::*;
use frame_support::traits::{EnsureOriginWithArg, Hooks};
use sp_runtime::{traits::Zero, Saturating};
use xcm::prelude::*;

/// Pallet we're benchmarking here.
pub struct Pallet<T: Config<I>, I: 'static = ()>(crate::Pallet<T, I>);

/// Trait that must be implemented by runtime to be able to benchmark pallet properly.
pub trait Config<I: 'static>: crate::Config<I> {
/// Fill up queue so it becomes congested.
fn make_congested();

/// Returns destination which is valid for this router instance.
/// (Needs to pass `T::Bridges`)
/// Make sure that `SendXcm` will pass.
fn ensure_bridged_target_destination() -> Result<Location, BenchmarkError> {
Ok(Location::new(
Self::UniversalLocation::get().len() as u8,
[GlobalConsensus(Self::BridgedNetworkId::get().unwrap())],
))
}
fn ensure_bridged_target_destination() -> Result<Location, BenchmarkError>;
/// Returns valid origin for `update_bridge_status` (if `T::BridgeHubOrigin` is supported).
fn update_bridge_status_origin() -> Option<Self::RuntimeOrigin>;
}

benchmarks_instance_pallet! {
on_initialize_when_non_congested {
DeliveryFeeFactor::<T, I>::put(MINIMAL_DELIVERY_FEE_FACTOR + MINIMAL_DELIVERY_FEE_FACTOR);
}: {
crate::Pallet::<T, I>::on_initialize(Zero::zero())
#[instance_benchmarks]
mod benchmarks {
use super::*;

#[benchmark]
fn on_idle_when_bridge_state_removed() -> Result<(), BenchmarkError> {
let bridge_id =
T::BridgeIdResolver::resolve_for_dest(&T::ensure_bridged_target_destination()?)
.ok_or(BenchmarkError::Weightless)?;

// uncongested and less than a minimal factor is removed
Bridges::<T, I>::insert(
&bridge_id,
BridgeState { delivery_fee_factor: 0.into(), is_congested: false },
);
assert!(Bridges::<T, I>::get(&bridge_id).is_some());

#[block]
{
let _ = crate::Pallet::<T, I>::on_idle(Zero::zero(), Weight::MAX);
}

assert!(Bridges::<T, I>::get(bridge_id).is_none());

Ok(())
}

on_initialize_when_congested {
DeliveryFeeFactor::<T, I>::put(MINIMAL_DELIVERY_FEE_FACTOR + MINIMAL_DELIVERY_FEE_FACTOR);
let _ = T::ensure_bridged_target_destination()?;
T::make_congested();
}: {
crate::Pallet::<T, I>::on_initialize(Zero::zero())
#[benchmark]
fn on_indle_when_bridge_state_updated() -> Result<(), BenchmarkError> {
let bridge_id =
T::BridgeIdResolver::resolve_for_dest(&T::ensure_bridged_target_destination()?)
.ok_or(BenchmarkError::Weightless)?;

// uncongested and higher than a minimal factor is decreased
let old_delivery_fee_factor = MINIMAL_DELIVERY_FEE_FACTOR.saturating_mul(1000.into());
Bridges::<T, I>::insert(
&bridge_id,
BridgeState { delivery_fee_factor: old_delivery_fee_factor, is_congested: false },
);
assert!(Bridges::<T, I>::get(&bridge_id).is_some());

#[block]
{
let _ = crate::Pallet::<T, I>::on_idle(Zero::zero(), Weight::MAX);
}

assert!(
Bridges::<T, I>::get(bridge_id).unwrap().delivery_fee_factor < old_delivery_fee_factor
);
Ok(())
}

#[benchmark]
fn update_bridge_status() -> Result<(), BenchmarkError> {
let bridge_id =
T::BridgeIdResolver::resolve_for_dest(&T::ensure_bridged_target_destination()?)
.ok_or(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?;
let origin = T::update_bridge_status_origin()
.ok_or(BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?;
let _ = T::BridgeHubOrigin::try_origin(origin.clone(), &bridge_id)
.map_err(|_| BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)))?;
let is_congested = true;

#[extrinsic_call]
update_bridge_status(origin as T::RuntimeOrigin, bridge_id.clone(), is_congested);

assert_eq!(
Bridges::<T, I>::get(&bridge_id),
Some(BridgeState { delivery_fee_factor: MINIMAL_DELIVERY_FEE_FACTOR, is_congested })
);
Ok(())
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::TestRuntime);
}
Loading
Loading