polkadot-sdk icon indicating copy to clipboard operation
polkadot-sdk copied to clipboard

Bridges - Add improved congestion control mechanism

Open bkontur opened this issue 1 year ago • 26 comments

Closes: https://github.com/paritytech/polkadot-sdk/issues/5551 Closes: https://github.com/paritytech/polkadot-sdk/issues/5550

Context

Before permissionless lanes, bridges only supported hard-coded, static lanes. The congestion mechanism was based on sending Transact(report_bridge_status(is_congested)) from pallet-xcm-bridge-hub to pallet-xcm-bridge-hub-router. Depending on is_congested, we adjusted the fee factor to increase or decrease fees. This congestion mechanism relied on monitoring XCMP queues, which could cause issues like suspending the entire XCMP queue rather than just the affected bridge.

Additionally, we are progressing with deploying bridge message pallets/routing directly on AssetHub, where we don’t interact with XCMP to perform ExportXcm locally.

Description

This PR introduces two new pallets pallet-xcm-bridge and pallet-xcm-bridge-router. These pallets are designed to improve congestion handling for bridges. The main objective of this PR is to enhance the routing and management of messages between chains.

This PR re-introduces and improves congestion for bridges:

  • Enhanced Bridge Congestion Mechanism: The bridge queue mechanism has been restructured to operate independently of XCMP, with a refined protocol for congestion detection and suspension management (congested_threshold and stop_threshold).
  • Bridge-Specific Channel Suspension: pallet-xcm-bridge and pallet-xcm-bridge-router now use BridgeId to identify specific bridges, enabling selective suspension and resumption of individual bridge channels.
  • Dynamic Congestion Detection: pallet-xcm-bridge now includes callbacks for fn suspend_bridge and fn resume_bridge based on congestion status:
    • For sibling chains, the pallet-xcm-bridges exporter can send xcm::Transact(update_bridge_status(bridge_id, is_congested)) using the stored callback information.
    • For local chain deployments, the pallet-xcm-bridge's exporter manages state directly.
  • New Stop Threshold: A stop_threshold limit in pallet-xcm-bridge enables or disables ExportXcm::validate, providing a fallback mechanism when the router does not adhere to the suspend signal.
  • Flexible Message Routing: pallet-xcm-bridge-router has support for message routing for both sibling chains (ExportMessage - ViaRemoteBridgeExporter) and local deployment (ExportXcm - ViaLocalBridgeExporter).

Open questions

  • [ ] when the router receives is_congested = false with fn do_update_bridge_status(, can we directly remove it (its fee factor) from Bridges and the next message fee wont be affected by increased fee factor or slowly start decreasing fee factor on idle (this is how it is implemented now)? Original comment

bkontur avatar Oct 25 '24 08:10 bkontur