Skip to content

Commit

Permalink
Snowbridge Headers on Demand (#365)
Browse files Browse the repository at this point in the history
Upgrades Snowbridge to have a much more cost effective Ethereum light
client. In the current light client in production, all Ethereum
execution headers are stored, whether they contain a transfer message or
not. This PR upgrades Snowbridge to not store execution headers at all,
but provide the execution header proof alongside a message. Ethereum
beacon headers are still stored, to track finalized headers and do
ancestry proofs.

More details on the change on the original PR:
paritytech/polkadot-sdk#3761

---------

Co-authored-by: Branislav Kontur <[email protected]>
claravanstaden and bkontur authored Jul 3, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent b900992 commit 78c4600
Showing 19 changed files with 423 additions and 551 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed

- Polkadot chains: allow arbitrary XCM execution ([polkadot-fellows/runtimes#345](https://github.com/polkadot-fellows/runtimes/pull/345))
- Snowbridge: Sync headers on demand ([polkadot-fellows/runtimes#345](https://github.com/polkadot-fellows/runtimes/pull/365))

## [1.2.7] 14.06.2024

48 changes: 24 additions & 24 deletions Cargo.lock

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

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -189,17 +189,17 @@ separator = { version = "0.4.1" }
serde = { version = "1.0.196" }
serde_json = { version = "1.0.113" }
smallvec = { version = "1.13.1" }
snowbridge-beacon-primitives = { version = "0.1.0", default-features = false }
snowbridge-core = { version = "0.1.1", default-features = false }
snowbridge-beacon-primitives = { version = "0.1.2", default-features = false }
snowbridge-core = { version = "0.1.3", default-features = false }
snowbridge-outbound-queue-runtime-api = { version = "0.1.1", default-features = false }
snowbridge-pallet-ethereum-client = { version = "0.1.2", default-features = false }
snowbridge-pallet-inbound-queue = { version = "0.1.1", default-features = false }
snowbridge-pallet-inbound-queue-fixtures = { version = "0.9.0" }
snowbridge-pallet-ethereum-client = { version = "0.1.3", default-features = false }
snowbridge-pallet-inbound-queue = { version = "0.1.3", default-features = false }
snowbridge-pallet-inbound-queue-fixtures = { version = "0.9.1" }
snowbridge-pallet-outbound-queue = { version = "0.1.1", default-features = false }
snowbridge-pallet-system = { version = "0.1.1", default-features = false }
snowbridge-router-primitives = { version = "0.1.0", default-features = false }
snowbridge-runtime-common = { version = "0.1.0", default-features = false }
snowbridge-runtime-test-common = { version = "0.1.0" }
snowbridge-runtime-test-common = { version = "0.1.2" }
snowbridge-system-runtime-api = { version = "0.1.0", default-features = false }
sp-api = { version = "27.0.1", default-features = false }
sp-application-crypto = { version = "31.0.0", default-features = false }

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
@@ -161,7 +161,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("kusama"),
impl_name: create_runtime_str!("parity-kusama"),
authoring_version: 2,
spec_version: 1_002_006,
spec_version: 1_002_008,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 26,
2 changes: 1 addition & 1 deletion relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -155,7 +155,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("polkadot"),
impl_name: create_runtime_str!("parity-polkadot"),
authoring_version: 0,
spec_version: 1_002_007,
spec_version: 1_002_008,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 26,
4 changes: 2 additions & 2 deletions system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("statemine"),
impl_name: create_runtime_str!("statemine"),
authoring_version: 1,
spec_version: 1_002_006,
spec_version: 1_002_008,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 15,
@@ -128,7 +128,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("statemine"),
impl_name: create_runtime_str!("statemine"),
authoring_version: 1,
spec_version: 1_002_006,
spec_version: 1_002_008,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 15,
2 changes: 1 addition & 1 deletion system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -146,7 +146,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("statemint"),
impl_name: create_runtime_str!("statemint"),
authoring_version: 1,
spec_version: 1_002_006,
spec_version: 1_002_008,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 15,
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ impl snowbridge_pallet_outbound_queue::Config for Runtime {
type Channels = EthereumSystem;
}

#[cfg(not(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test)))]
#[cfg(not(any(feature = "std", feature = "runtime-benchmarks", test)))]
parameter_types! {
pub const ChainForkVersions: ForkVersions = ForkVersions {
genesis: Fork {
@@ -113,7 +113,7 @@ parameter_types! {
};
}

#[cfg(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test))]
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
parameter_types! {
pub const ChainForkVersions: ForkVersions = ForkVersions {
genesis: Fork {
@@ -139,17 +139,9 @@ parameter_types! {
};
}

parameter_types! {
// On Ethereum, a sync committee period spans 8192 slots, approximately 27 hours (or 256 epochs).
// We retain headers for 20 sync committee periods, equating to about 3 weeks. Headers older
// than this period are pruned.
pub const MaxExecutionHeadersToKeep: u32 = 8192 * 20;
}

impl snowbridge_pallet_ethereum_client::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ForkVersions = ChainForkVersions;
type MaxExecutionHeadersToKeep = MaxExecutionHeadersToKeep;
type WeightInfo = crate::weights::snowbridge_pallet_ethereum_client::WeightInfo<Runtime>;
}

@@ -174,14 +166,14 @@ pub mod benchmark_helpers {
use codec::Encode;
use frame_support::traits::fungible;
use hex_literal::hex;
use snowbridge_beacon_primitives::CompactExecutionHeader;
use snowbridge_beacon_primitives::BeaconHeader;
use snowbridge_pallet_inbound_queue::BenchmarkHelper;
use sp_core::H256;
use xcm::latest::{Assets, Location, SendError, SendResult, SendXcm, Xcm, XcmHash};

impl<T: snowbridge_pallet_ethereum_client::Config> BenchmarkHelper<T> for Runtime {
fn initialize_storage(block_hash: H256, header: CompactExecutionHeader) {
EthereumBeaconClient::store_execution_header(block_hash, header, 0, H256::default());
fn initialize_storage(beacon_header: BeaconHeader, block_roots_root: H256) {
EthereumBeaconClient::store_finalized_header(beacon_header, block_roots_root).unwrap();
EthereumGatewayAddress::set(&hex!["EDa338E4dC46038493b885327842fD3E301CaB39"].into());
}
}
2 changes: 1 addition & 1 deletion system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
@@ -166,7 +166,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_006,
spec_version: 1_002_008,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 5,

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

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
@@ -87,7 +87,7 @@ impl snowbridge_pallet_outbound_queue::Config for Runtime {
type Channels = EthereumSystem;
}

#[cfg(not(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test)))]
#[cfg(not(any(feature = "std", feature = "runtime-benchmarks", test)))]
parameter_types! {
pub const ChainForkVersions: ForkVersions = ForkVersions {
genesis: Fork {
@@ -113,7 +113,7 @@ parameter_types! {
};
}

#[cfg(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test))]
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
parameter_types! {
pub const ChainForkVersions: ForkVersions = ForkVersions {
genesis: Fork {
@@ -139,17 +139,9 @@ parameter_types! {
};
}

parameter_types! {
// On Ethereum, a sync committee period spans 8192 slots, approximately 27 hours (or 256 epochs).
// We retain headers for 20 sync committee periods, equating to about 3 weeks. Headers older
// than this period are pruned.
pub const MaxExecutionHeadersToKeep: u32 = 8192 * 20;
}

impl snowbridge_pallet_ethereum_client::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ForkVersions = ChainForkVersions;
type MaxExecutionHeadersToKeep = MaxExecutionHeadersToKeep;
type WeightInfo = crate::weights::snowbridge_pallet_ethereum_client::WeightInfo<Runtime>;
}

@@ -174,14 +166,14 @@ pub mod benchmark_helpers {
use codec::Encode;
use frame_support::traits::fungible;
use hex_literal::hex;
use snowbridge_beacon_primitives::CompactExecutionHeader;
use snowbridge_beacon_primitives::BeaconHeader;
use snowbridge_pallet_inbound_queue::BenchmarkHelper;
use sp_core::H256;
use xcm::latest::{Assets, Location, SendError, SendResult, SendXcm, Xcm, XcmHash};

impl<T: snowbridge_pallet_ethereum_client::Config> BenchmarkHelper<T> for Runtime {
fn initialize_storage(block_hash: H256, header: CompactExecutionHeader) {
EthereumBeaconClient::store_execution_header(block_hash, header, 0, H256::default());
fn initialize_storage(beacon_header: BeaconHeader, block_roots_root: H256) {
EthereumBeaconClient::store_finalized_header(beacon_header, block_roots_root).unwrap();
EthereumGatewayAddress::set(&hex!["EDa338E4dC46038493b885327842fD3E301CaB39"].into());
}
}

This file was deleted.

This file was deleted.

6 changes: 1 addition & 5 deletions system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -23,9 +23,7 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

pub mod bridge_to_ethereum_config;
mod bridge_to_ethereum_unstuck;
pub mod bridge_to_kusama_config;
mod bridge_to_kusama_unstuck;
mod weights;
pub mod xcm_config;

@@ -151,8 +149,6 @@ pub type Migrations = (
ConstU32<BRIDGE_HUB_ID>,
ConstU32<ASSET_HUB_ID>,
>,
bridge_to_kusama_unstuck::BridgeToKusamaUnstuck,
bridge_to_ethereum_unstuck::UnstuckSnowbridge,
pallet_collator_selection::migration::v2::MigrationToV2<Runtime>,
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
@@ -179,7 +175,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("bridge-hub-polkadot"),
impl_name: create_runtime_str!("bridge-hub-polkadot"),
authoring_version: 1,
spec_version: 1_002_006,
spec_version: 1_002_008,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 4,

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

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

0 comments on commit 78c4600

Please sign in to comment.