Skip to content

Commit

Permalink
Unstuck Polkadot<>Kusama bridge (#277)
Browse files Browse the repository at this point in the history
The `pallet_bridge_grandpa` at Polkadot Bridge Hub is now in
inconsistent state, because of:
paritytech/polkadot-sdk#4208.

This PR does three thinds:
1) bumps `bp_header_chain` dependency to avoid having this issue in the
future;
2) adds an upgrade to Polkadot BH, which will fix the
`pallet_bridge_grandpa::CurrentAuthoritySet` storage value;
3) changes `SafeXcmFilter` to allow changing
`pallet_bridge_grandpa::CurrentAuthoritySet` using `set_storage` call in
the future.

We'll need to do a patch release and upgrade Polkadot and Kusama BH.
I've created this PR for master branch, but we can fork off from `1.2.0`
tag and duplicate it there.

Below some tests that are reproducible, so anyone can check it

---

How to ensure that current Polkadot BH is broken:
1) download/clone
https://github.com/AcalaNetwork/chopsticks/blob/master/configs/polkadot-bridge-hub.yml;
2) start chopsticks: `npx @acala-network/chopsticks@latest xcm -r
polkadot -p configs/polkadot-bridge-hub.yml -p polkadot-bridge-hub`;
3) start `substrate-relay` (`cargo build -p substrate-relay` in
`https://github.com/paritytech/parity-bridges-common/`):
```sh
RUST_LOG=bridge=trace ./target/release/substrate-relay relay-headers kusama-to-bridge-hub-polkadot \
    --source-uri wss://apps-kusama-rpc.polkadot.io:443 \
    --source-version-mode Auto \
    --target-uri ws://localhost:8000 \
    --target-version-mode Auto \
    --target-signer //Alice \
    --target-transactions-mortality 16 \
	--only-mandatory-headers
```
4) wait and see that it fails:
```sh
2024-04-19 13:26:10 +00 INFO bridge Connecting to Kusama node at wss://apps-kusama-rpc.polkadot.io:443
2024-04-19 13:26:10 +00 INFO bridge Connecting to BridgeHubPolkadot node at ws://localhost:8000
2024-04-19 13:26:10 +00 INFO bridge Exposed substrate_relay_build_info metric: version=0.1.0 commit=bb7d2186d6-clean
2024-04-19 13:26:10 +00 INFO bridge Starting Kusama -> BridgeHubPolkadot finality proof relay
2024-04-19 13:26:10 +00 TRACE bridge-metrics Refreshed process metrics: CPU=0.000064708678110037, memory=29766975488
2024-04-19 13:26:10 +00 TRACE bridge-metrics Starting prometheus endpoint at: 127.0.0.1:9616
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:26:10 +00 WARN bridge Kusama finality proofs stream is being started / restarted
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:26:11 +00 INFO bridge Synced 22780167 of 22807058 headers
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:26:11 +00 TRACE bridge Considering range of headers (22780167; 22807058]
2024-04-19 13:26:20 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.3793294429779053, memory=47601156096
2024-04-19 13:26:30 +00 TRACE bridge-metrics Refreshed process metrics: CPU=1.91074800491333, memory=48406462464
2024-04-19 13:26:40 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.21091628074646, memory=48406462464
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:26:50 +00 TRACE bridge Header 22780416 has persistent finality proof
2024-04-19 13:26:50 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.7086338996887207, memory=59814969344
2024-04-19 13:27:00 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.6120808124542236, memory=59949187072
2024-04-19 13:27:10 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.3101067543029785, memory=65183678464
2024-04-19 13:27:20 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.5125627517700195, memory=65183678464
2024-04-19 13:27:30 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.8137168884277344, memory=65183678464
2024-04-19 13:27:40 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.511143207550049, memory=65183678464
2024-04-19 13:27:50 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.5087807178497314, memory=65183678464
2024-04-19 13:28:00 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.6122448444366455, memory=65183678464
2024-04-19 13:28:10 +00 TRACE bridge-metrics Refreshed process metrics: CPU=3.0101592540740967, memory=65183678464
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:28:12 +00 TRACE bridge Header 22780928 has persistent finality proof
2024-04-19 13:28:20 +00 TRACE bridge-metrics Refreshed process metrics: CPU=1.8107513189315796, memory=68807557120
2024-04-19 13:28:30 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.713397264480591, memory=68807557120
2024-04-19 13:28:40 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.4137279987335205, memory=68807557120
2024-04-19 13:28:50 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.9156715869903564, memory=68807557120
2024-04-19 13:29:00 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.1125431060791016, memory=68807557120
2024-04-19 13:29:10 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.113739252090454, memory=68807557120
2024-04-19 13:29:20 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.2080039978027344, memory=68807557120
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:29:30 +00 TRACE bridge Header 22781365 is mandatory
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:29:30 +00 DEBUG bridge Going to submit finality proof of Kusama header #22781365 to BridgeHubPolkadot
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:29:30 +00 ERROR bridge Finality sync loop iteration has failed with error: Target(Custom("Failed to optimize Kusama GRANDPA jutification for header HeaderId(22781365, 0x412ee6710afc4b2a835f31c7139bc0697845256d7e39ee77ace2a09c04b4e2d1): Error::TooLowCumulativeWeight"))
```

How to ensure that the fix works:
1) build upgraded Polkadot BH runtime:
```sh
srtool build --root --package bridge-hub-polkadot-runtime --runtime-dir system-parachains/bridge-hubs/bridge-hub-polkadot/
```
2) download/clone
https://github.com/AcalaNetwork/chopsticks/blob/master/configs/polkadot-bridge-hub.yml;
3) "patch" yml file ^^^ by adding:
```
wasm-override: /home/svyatonik/dev/runtimes/system-parachains/bridge-hubs/bridge-hub-polkadot/target/srtool/release/wbuild/bridge-hub-polkadot-runtime/bridge_hub_polkadot_runtime.compact.compressed.wasm
```
4) start chopsticks: `npx @acala-network/chopsticks@latest xcm -r
polkadot -p configs/polkadot-bridge-hub.yml -p polkadot-bridge-hub`;
5) the runtime is not yet upgraded - go to
https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A8000#/chainstate
and check that `bridgeKusamaGrandpa.currentAuthoritySet.setId` is 8905;
6) upgrade BH runtime (and run migrations):
```sh
wscat -c ws://127.0.0.1:8002 -x '{ "jsonrpc": "2.0", "id": 1, "method": "dev_newBlock", "params": [{"count": 1 }] }'
wscat -c ws://127.0.0.1:8000 -x '{ "jsonrpc": "2.0", "id": 1, "method": "dev_newBlock", "params": [{"count": 1 }] }'
```
7) go to
https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A8000#/chainstate
and check that `bridgeKusamaGrandpa.currentAuthoritySet.setId` is
changed to 8906;
8) start **fixed** `substrate-relay` (soon to be updated: `cargo build
-p substrate-relay` in
`https://github.com/paritytech/parity-bridges-common/`):
```sh
RUST_LOG=bridge=trace ./target/release/substrate-relay relay-headers kusama-to-bridge-hub-polkadot \
    --source-uri wss://apps-kusama-rpc.polkadot.io:443 \
    --source-version-mode Auto \
    --target-uri ws://localhost:8000 \
    --target-version-mode Auto \
    --target-signer //Alice \
    --target-transactions-mortality 16 \
	--only-mandatory-headers
```
9) wait and see that it works:
```sh
024-04-19 13:36:09 +00 INFO bridge Connecting to Kusama node at wss://apps-kusama-rpc.polkadot.io:443
2024-04-19 13:36:10 +00 INFO bridge Connecting to BridgeHubPolkadot node at ws://localhost:8000
2024-04-19 13:36:10 +00 INFO bridge Exposed substrate_relay_build_info metric: version=0.1.0 commit=bb7d2186d6-clean
2024-04-19 13:36:10 +00 INFO bridge Starting Kusama -> BridgeHubPolkadot finality proof relay
2024-04-19 13:36:10 +00 TRACE bridge-metrics Refreshed process metrics: CPU=0, memory=29938941952
2024-04-19 13:36:10 +00 TRACE bridge-metrics Starting prometheus endpoint at: 127.0.0.1:9616
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:36:10 +00 WARN bridge Kusama finality proofs stream is being started / restarted
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:36:11 +00 INFO bridge Synced 22780167 of 22807159 headers
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:36:11 +00 TRACE bridge Considering range of headers (22780167; 22807159]
2024-04-19 13:36:20 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.193419933319092, memory=45940211712
2024-04-19 13:36:30 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.3150477409362793, memory=45940211712
2024-04-19 13:36:40 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.6142148971557617, memory=52919533568
2024-04-19 13:36:50 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.4085805416107178, memory=54932799488
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:36:51 +00 TRACE bridge Header 22780416 has persistent finality proof
2024-04-19 13:37:00 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.7103331089019775, memory=58690895872
2024-04-19 13:37:10 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.608804702758789, memory=58690895872
2024-04-19 13:37:20 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.9072680473327637, memory=58690895872
2024-04-19 13:37:30 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.810892343521118, memory=58690895872
2024-04-19 13:37:40 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.810363292694092, memory=62046339072
2024-04-19 13:37:50 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.91256046295166, memory=62046339072
2024-04-19 13:38:00 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.8086013793945313, memory=62046339072
2024-04-19 13:38:10 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.9083614349365234, memory=64864911360
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:38:18 +00 TRACE bridge Header 22780928 has persistent finality proof
2024-04-19 13:38:20 +00 TRACE bridge-metrics Refreshed process metrics: CPU=3.109522819519043, memory=68354572288
2024-04-19 13:38:30 +00 TRACE bridge-metrics Refreshed process metrics: CPU=3.2074172496795654, memory=68354572288
2024-04-19 13:38:40 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.90763258934021, memory=68354572288
2024-04-19 13:38:50 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.9101855754852295, memory=68354572288
2024-04-19 13:39:00 +00 TRACE bridge-metrics Refreshed process metrics: CPU=3.0146965980529785, memory=68354572288
2024-04-19 13:39:10 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.6119167804718018, memory=68354572288
2024-04-19 13:39:20 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.3114125728607178, memory=68354572288
2024-04-19 13:39:30 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.811950922012329, memory=68354572288
2024-04-19 13:39:40 +00 TRACE bridge-metrics Refreshed process metrics: CPU=2.3072102069854736, memory=68354572288
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:39:46 +00 TRACE bridge Header 22781365 is mandatory
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:39:46 +00 DEBUG bridge Going to submit finality proof of Kusama header #22781365 to BridgeHubPolkadot
2024-04-19 13:39:46 +00 TRACE bridge Sent transaction to BridgeHubPolkadot node: 0x0d7a80fec36ede67860f89028fb336009f82fef406ca31adaafcae54fa067e0d
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:39:48 +00 TRACE bridge BridgeHubPolkadot transaction 0x0d7a80fec36ede67860f89028fb336009f82fef406ca31adaafcae54fa067e0d has been included in block: (0xedf5af02e37da014a5b8e53325821f3618d80f1c75b62105aada4b6506919156, 0)
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:39:48 +00 TRACE bridge BridgeHubPolkadot transaction 0x0d7a80fec36ede67860f89028fb336009f82fef406ca31adaafcae54fa067e0d has been finalized at block: 0xedf5af02e37da014a5b8e53325821f3618d80f1c75b62105aada4b6506919156
[Kusama_to_BridgeHubPolkadot_Sync] 2024-04-19 13:39:49 +00 INFO bridge Synced 22781365 of 22807194 headers
```
10) you can check Polkadot BH state and see that the new `bestFinalized`
is `22781365`.

---------

Co-authored-by: Adrian Catangiu <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
3 people authored Apr 19, 2024
1 parent 31ba262 commit b5647c4
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 302 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ Changelog for the runtimes governed by the Polkadot Fellowship.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased
## [Unreleased]

- Add `pallet-vesting` to Asset Hubs ([polkadot-fellows/runtimes#269](https://github.com/polkadot-fellows/runtimes/pull/269))

### Fixed

- Bumped `bp-header-chain` dependency and added migration to Polkadot Bridge Hub to unstuck
bridge with Kusama. Details may be found in relevant
[polkadot-sdk](https://github.com/paritytech/polkadot-sdk/pull/4208) PR.

## [1.2.1] 09.04.2024

### Changed
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ asset-test-utils = { version = "8.0.1" }
assets-common = { version = "0.8.0", default-features = false }
binary-merkle-tree = { version = "14.0.0", default-features = false }
bp-bridge-hub-cumulus = { version = "0.8.0", default-features = false }
bp-header-chain = { version = "0.8.0", default-features = false }
bp-header-chain = { version = "0.8.1", default-features = false }
bp-kusama = { version = "0.6.0", default-features = false }
bp-messages = { version = "0.8.0", default-features = false }
bp-parachains = { version = "0.8.0", default-features = false }
Expand Down
20 changes: 7 additions & 13 deletions system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,13 +747,6 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type PriceForSiblingDelivery = PriceForSiblingParachainDelivery;
}

// TODO: remove dmp with 1.3.0 (https://github.com/polkadot-fellows/runtimes/issues/186)
impl cumulus_pallet_dmp_queue::Config for Runtime {
type WeightInfo = weights::cumulus_pallet_dmp_queue::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
type DmpSink = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
}

parameter_types! {
pub const Period: u32 = 6 * HOURS;
pub const Offset: u32 = 0;
Expand Down Expand Up @@ -972,9 +965,7 @@ construct_runtime!(
XcmpQueue: cumulus_pallet_xcmp_queue = 30,
PolkadotXcm: pallet_xcm = 31,
CumulusXcm: cumulus_pallet_xcm = 32,
// TODO: remove dmp with 1.3.0 (https://github.com/polkadot-fellows/runtimes/issues/186)
// Temporary to migrate the remaining DMP messages:
DmpQueue: cumulus_pallet_dmp_queue = 33,
// DmpQueue = 33
ToPolkadotXcmRouter: pallet_xcm_bridge_hub_router::<Instance1> = 34,
MessageQueue: pallet_message_queue = 35,

Expand Down Expand Up @@ -1020,10 +1011,14 @@ pub type SignedExtra = (
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

parameter_types! {
pub DmpQueueName: &'static str = "DmpQueue";
}

/// Migrations to apply on runtime upgrade.
pub type Migrations = (
// unreleased
cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4<Runtime>,
frame_support::migrations::RemovePallet<DmpQueueName, RocksDbWeight>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);
Expand Down Expand Up @@ -1060,7 +1055,6 @@ mod benches {
[pallet_collator_selection, CollatorSelection]
[cumulus_pallet_parachain_system, ParachainSystem]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[cumulus_pallet_dmp_queue, DmpQueue]
// XCM
[pallet_xcm, PalletXcmExtrinsiscsBenchmark::<Runtime>]
// Bridges
Expand Down

This file was deleted.

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

Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ impl Contains<RuntimeCall> for SafeCallFilter {
pallet_collator_selection::Call::remove_invulnerable { .. },
) | RuntimeCall::Session(pallet_session::Call::purge_keys { .. }) |
RuntimeCall::XcmpQueue(..) |
RuntimeCall::DmpQueue(..) |
RuntimeCall::Assets(
pallet_assets::Call::create { .. } |
pallet_assets::Call::force_create { .. } |
Expand Down
26 changes: 6 additions & 20 deletions system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ use xcm_config::{FellowshipLocation, GovernanceLocation, XcmOriginToTransactDisp
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;

use kusama_runtime_constants::system_parachain::{ASSET_HUB_ID, BRIDGE_HUB_ID};
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};

use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
Expand Down Expand Up @@ -132,15 +131,13 @@ bridge_runtime_common::generate_bridge_reject_obsolete_headers_and_messages! {
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

parameter_types! {
pub DmpQueueName: &'static str = "DmpQueue";
}

/// Migrations to apply on runtime upgrade.
pub type Migrations = (
// unreleased
cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4<Runtime>,
snowbridge_pallet_system::migration::v0::InitializeOnUpgrade<
Runtime,
ConstU32<BRIDGE_HUB_ID>,
ConstU32<ASSET_HUB_ID>,
>,
frame_support::migrations::RemovePallet<DmpQueueName, RocksDbWeight>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
);
Expand All @@ -166,7 +163,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("bridge-hub-kusama"),
impl_name: create_runtime_str!("bridge-hub-kusama"),
authoring_version: 1,
spec_version: 1_002_000,
spec_version: 1_002_002,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 4,
Expand Down Expand Up @@ -413,13 +410,6 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type PriceForSiblingDelivery = PriceForSiblingParachainDelivery;
}

// TODO: remove dmp with 1.3.0 (https://github.com/polkadot-fellows/runtimes/issues/186)
impl cumulus_pallet_dmp_queue::Config for Runtime {
type WeightInfo = weights::cumulus_pallet_dmp_queue::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
type DmpSink = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
}

pub const PERIOD: u32 = 6 * HOURS;
pub const OFFSET: u32 = 0;

Expand Down Expand Up @@ -523,9 +513,6 @@ construct_runtime!(
XcmpQueue: cumulus_pallet_xcmp_queue = 30,
PolkadotXcm: pallet_xcm = 31,
CumulusXcm: cumulus_pallet_xcm = 32,
// TODO: remove dmp with 1.3.0 (https://github.com/polkadot-fellows/runtimes/issues/186)
// Temporary to migrate the remaining DMP messages:
DmpQueue: cumulus_pallet_dmp_queue = 33,

// Handy utilities.
Utility: pallet_utility = 40,
Expand Down Expand Up @@ -565,7 +552,6 @@ mod benches {
[pallet_collator_selection, CollatorSelection]
[cumulus_pallet_parachain_system, ParachainSystem]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[cumulus_pallet_dmp_queue, DmpQueue]
// XCM
[pallet_xcm, PalletXcmExtrinsiscsBenchmark::<Runtime>]
// NOTE: Make sure you point to the individual modules below.
Expand Down
Loading

0 comments on commit b5647c4

Please sign in to comment.