From 237f0cab00a1d5eda96e764b610639e3a9d51698 Mon Sep 17 00:00:00 2001 From: claravanstaden Date: Mon, 5 Feb 2024 10:35:45 +0200 Subject: [PATCH] update bridge hub --- .../asset-hubs/asset-hub-kusama/Cargo.toml | 1 - .../asset-hubs/asset-hub-polkadot/Cargo.toml | 1 - .../bridge-hubs/bridge-hub-kusama/Cargo.toml | 7 +- .../src/bridge_to_ethereum_config.rs | 2 +- .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 179 +++++++++-------- .../bridge-hub-kusama/src/xcm_config.rs | 55 +++--- .../bridge-hub-polkadot/Cargo.toml | 8 +- .../src/bridge_to_ethereum_config.rs | 2 +- .../bridge-hub-polkadot/src/lib.rs | 180 ++++++++++-------- .../bridge-hub-polkadot/src/xcm_config.rs | 53 +++--- 10 files changed, 262 insertions(+), 226 deletions(-) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml index 95e858f048..30cbab8a26 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml @@ -95,7 +95,6 @@ assets-common = { default-features = false , version = "0.6.0" } # Bridges pallet-xcm-bridge-hub-router = { default-features = false , version = "0.4.0" } snowbridge-router-primitives = { default-features = false , version = "1.0.0" } #todo publish -snowbridge-kusama-common = { default-features = false , version = "1.0.0" } #todo publish [dev-dependencies] diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml index 64373ab8f0..a4f41dede5 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml @@ -90,7 +90,6 @@ assets-common = { default-features = false , version = "0.6.0" } # Bridges pallet-xcm-bridge-hub-router = { default-features = false , version = "0.4.0" } snowbridge-router-primitives = { default-features = false, version = "1.0.0" } #todo publish -snowbridge-polkadot-common = { default-features = false, version = "1.0.0" } #todo publish [dev-dependencies] hex-literal = "0.4.1" diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml index 8b65821222..b8b4732fe0 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -121,13 +121,12 @@ snowbridge-beacon-primitives = { default-features = false , version = "1.0.0" } snowbridge-system = { default-features = false , version = "1.0.0" } snowbridge-system-runtime-api = { default-features = false , version = "1.0.0" } snowbridge-core = { default-features = false , version = "1.0.0" } -snowbridge-ethereum-beacon-client = { default-features = false , version = "1.0.0" } -snowbridge-inbound-queue = { default-features = false , version = "1.0.0" } -snowbridge-outbound-queue = { default-features = false , version = "1.0.0" } +snowbridge-pallet-ethereum-client = { default-features = false , version = "1.0.0" } +snowbridge-pallet-inbound-queue = { default-features = false , version = "1.0.0" } +snowbridge-pallet-outbound-queue = { default-features = false , version = "1.0.0" } snowbridge-outbound-queue-runtime-api = { default-features = false , version = "1.0.0" } snowbridge-router-primitives = { default-features = false , version = "1.0.0" } snowbridge-runtime-common = { default-features = false , version = "1.0.0" } -snowbridge-kusama-common = { default-features = false , version = "1.0.0" } [dev-dependencies] bridge-hub-test-utils = { version = "0.6.0" } diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/bridge_to_ethereum_config.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/bridge_to_ethereum_config.rs index 5ef402c002..3ff3c15dbc 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/bridge_to_ethereum_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/bridge_to_ethereum_config.rs @@ -18,7 +18,7 @@ use crate::{ xcm_config::UniversalLocation, Runtime, }; -use snowbridge_kusama_common::EthereumNetwork; +use system_parachains_constants::kusama::snowbridge::EthereumNetwork; use snowbridge_router_primitives::outbound::EthereumBlobExporter; /// Exports message to the Ethereum Gateway contract. diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs index dc648e1f0b..5f0e22d017 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -28,6 +28,7 @@ mod weights; pub mod xcm_config; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use cumulus_primitives_core::ParaId; use snowbridge_beacon_primitives::{Fork, ForkVersions}; use snowbridge_core::{ gwei, meth, outbound::Message, AgentId, AllowSiblingsOnly, PricingParameters, Rewards, @@ -48,12 +49,6 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; -#[cfg(not(feature = "runtime-benchmarks"))] -use bridge_hub_common::BridgeHubMessageRouter; -use bridge_hub_common::{ - message_queue::{NarrowOriginToSibling, ParaIdToSibling}, - AggregateMessageOrigin, -}; use cumulus_primitives_core::ParaId; use frame_support::{ construct_runtime, @@ -90,6 +85,8 @@ use parachains_common::{ impls::DealWithFees, message_queue::*, AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature, }; + +use polkadot_runtime_common::prod_or_fast; use system_parachains_constants::{ kusama::{consensus::*, currency::*, fee::WeightToFee}, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, @@ -99,17 +96,9 @@ use system_parachains_constants::{ use xcm::prelude::*; #[cfg(feature = "runtime-benchmarks")] -use crate::xcm_config::benchmark_helpers::DoNothingRouter; -#[cfg(feature = "runtime-benchmarks")] -use snowbridge_beacon_primitives::CompactExecutionHeader; -#[cfg(feature = "runtime-benchmarks")] -use snowbridge_core::RingBufferMap; -#[cfg(feature = "runtime-benchmarks")] -pub use snowbridge_ethereum_beacon_client::ExecutionHeaderBuffer; -#[cfg(feature = "runtime-benchmarks")] -use snowbridge_inbound_queue::BenchmarkHelper; -#[cfg(feature = "runtime-benchmarks")] -use sp_core::H256; +use benchmark_helpers::DoNothingRouter; +#[cfg(not(feature = "runtime-benchmarks"))] +use bridge_hub_common::BridgeHubMessageRouter; /// The address format for describing accounts. pub type Address = MultiAddress; @@ -155,6 +144,11 @@ pub type UncheckedExtrinsic = pub type Migrations = ( // unreleased cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, + snowbridge_pallet_system::migration::v0::InitializeOnUpgrade< + Runtime, + ConstU32, + ConstU32, + >, ); /// Executive: handles dispatch to the various modules. @@ -344,21 +338,27 @@ impl cumulus_pallet_parachain_system::Config for Runtime { impl parachain_info::Config for Runtime {} parameter_types! { - pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block; + /// Amount of weight that can be spent per block to service messages. This was increased + /// from 35% to 60% of the max block weight to accommodate the Ethereum beacon light client + /// extrinsics. The force_checkpoint and submit extrinsics (for submit, optionally) includes + /// the sync committee's pubkeys (512 x 48 bytes) + pub MessageQueueServiceWeight: Weight = Perbill::from_percent(60) * RuntimeBlockWeights::get().max_block; } impl pallet_message_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::pallet_message_queue::WeightInfo; #[cfg(feature = "runtime-benchmarks")] - type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor< - cumulus_primitives_core::AggregateMessageOrigin, - >; + type MessageProcessor = + pallet_message_queue::mock_helpers::NoopMessageProcessor; #[cfg(not(feature = "runtime-benchmarks"))] - type MessageProcessor = xcm_builder::ProcessXcmMessage< - AggregateMessageOrigin, - xcm_executor::XcmExecutor, - RuntimeCall, + type MessageProcessor = BridgeHubMessageRouter< + xcm_builder::ProcessXcmMessage< + AggregateMessageOrigin, + xcm_executor::XcmExecutor, + RuntimeCall, + >, + EthereumOutboundQueue, >; type Size = u32; // The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin: @@ -371,8 +371,6 @@ impl pallet_message_queue::Config for Runtime { impl cumulus_pallet_aura_ext::Config for Runtime {} -// todo add message queue pallet config impl pallet_message_queue::Config for Runtime { - parameter_types! { // Fellows pluralistic body. pub const FellowsBodyId: BodyId = BodyId::Technical; @@ -501,13 +499,6 @@ impl pallet_utility::Config for Runtime { } // Ethereum Bridge - -#[cfg(not(feature = "runtime-benchmarks"))] -parameter_types! { - pub storage EthereumGatewayAddress: H160 = H160::zero(); -} - -#[cfg(feature = "runtime-benchmarks")] parameter_types! { pub storage EthereumGatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39")); } @@ -515,7 +506,7 @@ parameter_types! { parameter_types! { pub const CreateAssetCall: [u8;2] = [53, 0]; pub const CreateAssetDeposit: u128 = (UNITS / 10) + EXISTENTIAL_DEPOSIT; - pub const InboundQueuePalletInstance: u8 = snowbridge_kusama_common::INBOUND_QUEUE_MESSAGES_PALLET_INDEX; + pub const InboundQueuePalletInstance: u8 = system_parachains_constants::kusama::snowbridge::INBOUND_QUEUE_MESSAGES_PALLET_INDEX; pub Parameters: PricingParameters = PricingParameters { exchange_rate: FixedU128::from_rational(1, 400), fee_per_gas: gwei(20), @@ -524,15 +515,46 @@ parameter_types! { } #[cfg(feature = "runtime-benchmarks")] -impl BenchmarkHelper for Runtime { - fn initialize_storage(block_hash: H256, header: CompactExecutionHeader) { - >::insert(block_hash, header); +pub mod benchmark_helpers { + use crate::{EthereumBeaconClient, Runtime, RuntimeOrigin}; + use codec::Encode; + use snowbridge_beacon_primitives::CompactExecutionHeader; + use snowbridge_pallet_inbound_queue::BenchmarkHelper; + use sp_core::H256; + use xcm::latest::{Assets, Location, SendError, SendResult, SendXcm, Xcm, XcmHash}; + + impl BenchmarkHelper for Runtime { + fn initialize_storage(block_hash: H256, header: CompactExecutionHeader) { + EthereumBeaconClient::store_execution_header(block_hash, header, 0, H256::default()) + } + } + + pub struct DoNothingRouter; + impl SendXcm for DoNothingRouter { + type Ticket = Xcm<()>; + + fn validate( + _dest: &mut Option, + xcm: &mut Option>, + ) -> SendResult { + Ok((xcm.clone().unwrap(), Assets::new())) + } + fn deliver(xcm: Xcm<()>) -> Result { + let hash = xcm.using_encoded(sp_io::hashing::blake2_256); + Ok(hash) + } + } + + impl snowbridge_pallet_system::BenchmarkHelper for () { + fn make_xcm_origin(location: Location) -> RuntimeOrigin { + RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location)) + } } } -impl snowbridge_inbound_queue::Config for Runtime { +impl snowbridge_pallet_inbound_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type Verifier = snowbridge_ethereum_beacon_client::Pallet; + type Verifier = snowbridge_pallet_ethereum_client::Pallet; type Token = Balances; #[cfg(not(feature = "runtime-benchmarks"))] type XcmSender = XcmRouter; @@ -552,11 +574,12 @@ impl snowbridge_inbound_queue::Config for Runtime { type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier; type MaxMessageSize = ConstU32<2048>; - type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo; + type WeightInfo = weights::snowbridge_pallet_inbound_queue::WeightInfo; type PricingParameters = EthereumSystem; + type AssetTransactor = ::AssetTransactor; } -impl snowbridge_outbound_queue::Config for Runtime { +impl snowbridge_pallet_outbound_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Hashing = Keccak256; type MessageQueue = MessageQueue; @@ -566,35 +589,38 @@ impl snowbridge_outbound_queue::Config for Runtime { type GasMeter = snowbridge_core::outbound::ConstantGasMeter; type Balance = Balance; type WeightToFee = WeightToFee; - type WeightInfo = weights::snowbridge_outbound_queue::WeightInfo; + type WeightInfo = weights::snowbridge_pallet_outbound_queue::WeightInfo; type PricingParameters = EthereumSystem; type Channels = EthereumSystem; } -#[cfg(not(feature = "beacon-spec-mainnet"))] +#[cfg(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test))] parameter_types! { pub const ChainForkVersions: ForkVersions = ForkVersions { genesis: Fork { - version: [0, 0, 0, 1], // 0x00000001 + version: [0, 0, 0, 0], // 0x00000000 epoch: 0, }, altair: Fork { - version: [1, 0, 0, 1], // 0x01000001 + version: [1, 0, 0, 0], // 0x01000000 epoch: 0, }, bellatrix: Fork { - version: [2, 0, 0, 1], // 0x02000001 + version: [2, 0, 0, 0], // 0x02000000 epoch: 0, }, capella: Fork { - version: [3, 0, 0, 1], // 0x03000001 + version: [3, 0, 0, 0], // 0x03000000 epoch: 0, }, + deneb: Fork { + version: [4, 0, 0, 0], // 0x04000000 + epoch: 0, + } }; - pub const MaxExecutionHeadersToKeep:u32 = 1000; } -#[cfg(feature = "beacon-spec-mainnet")] +#[cfg(not(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test)))] parameter_types! { pub const ChainForkVersions: ForkVersions = ForkVersions { genesis: Fork { @@ -613,32 +639,32 @@ parameter_types! { version: [3, 0, 0, 0], // 0x03000000 epoch: 194048, }, + deneb: Fork { + version: [4, 0, 0, 0], // 0x04000000 + epoch: 99999999, // TODO update when epoch becomes known + }, }; - pub const MaxExecutionHeadersToKeep:u32 = 8192 * 2; } -impl snowbridge_ethereum_beacon_client::Config for Runtime { +parameter_types! { + pub const MaxExecutionHeadersToKeep: u32 = prod_or_fast!(8192 * 2, 1000); +} + +impl snowbridge_pallet_ethereum_client::Config for Runtime { type RuntimeEvent = RuntimeEvent; type ForkVersions = ChainForkVersions; type MaxExecutionHeadersToKeep = MaxExecutionHeadersToKeep; - type WeightInfo = weights::snowbridge_ethereum_beacon_client::WeightInfo; + type WeightInfo = weights::snowbridge_pallet_ethereum_client::WeightInfo; } -#[cfg(feature = "runtime-benchmarks")] -impl snowbridge_system::BenchmarkHelper for () { - fn make_xcm_origin(location: xcm::latest::MultiLocation) -> RuntimeOrigin { - RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location)) - } -} - -impl snowbridge_system::Config for Runtime { +impl snowbridge_pallet_system::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OutboundQueue = EthereumOutboundQueue; type SiblingOrigin = EnsureXcm; type AgentIdOf = snowbridge_core::AgentIdOf; type TreasuryAccount = TreasuryAccount; type Token = Balances; - type WeightInfo = weights::snowbridge_system::WeightInfo; + type WeightInfo = weights::snowbridge_pallet_system::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type Helper = (); type DefaultPricingParameters = Parameters; @@ -686,10 +712,13 @@ construct_runtime!( BridgePolkadotMessages: pallet_bridge_messages:: = 53, XcmOverBridgeHubPolkadot: pallet_xcm_bridge_hub:: = 54, - EthereumInboundQueue: snowbridge_inbound_queue = 80, - EthereumOutboundQueue: snowbridge_outbound_queue = 81, - EthereumBeaconClient: snowbridge_ethereum_beacon_client = 82, - EthereumSystem: snowbridge_system = 83, + // Ethereum bridge pallets. + EthereumInboundQueue: snowbridge_pallet_inbound_queue = 80, + EthereumOutboundQueue: snowbridge_pallet_inbound_queue = 81, + EthereumBeaconClient: snowbridge_pallet_ethereum_client = 82, + EthereumSystem: snowbridge_pallet_system = 83, + + // todo add message queue pallet here } ); @@ -719,10 +748,10 @@ mod benches { [pallet_bridge_parachains, PolkadotParachains] [pallet_bridge_messages, PolkadotMessages] // Ethereum Bridge - [snowbridge_inbound_queue, EthereumInboundQueue] - [snowbridge_outbound_queue, EthereumOutboundQueue] - [snowbridge_system, EthereumSystem] - [snowbridge_ethereum_beacon_client, EthereumBeaconClient] + [snowbridge_pallet_inbound_queue, EthereumInboundQueue] + [snowbridge_pallet_outbound_queue, EthereumOutboundQueue] + [snowbridge_pallet_system, EthereumSystem] + [snowbridge_pallet_ethereum_client, EthereumBeaconClient] ); } @@ -925,18 +954,18 @@ impl_runtime_apis! { } impl snowbridge_outbound_queue_runtime_api::OutboundQueueApi for Runtime { - fn prove_message(leaf_index: u64) -> Option { - snowbridge_outbound_queue::api::prove_message::(leaf_index) + fn prove_message(leaf_index: u64) -> Option { + snowbridge_pallet_outbound_queue::api::prove_message::(leaf_index) } fn calculate_fee(message: Message) -> Option { - snowbridge_outbound_queue::api::calculate_fee::(message) + snowbridge_pallet_outbound_queue::api::calculate_fee::(message) } } impl snowbridge_system_runtime_api::ControlApi for Runtime { - fn agent_id(location: VersionedMultiLocation) -> Option { - snowbridge_system::api::agent_id::(location) + fn agent_id(location: VersionedLocation) -> Option { + snowbridge_pallet_system::api::agent_id::(location) } } diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index b26686db8c..fd7a229caf 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -22,6 +22,7 @@ use super::{ PriceForParentDelivery, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, }; +use crate::EthereumGatewayAddress; use frame_support::{ match_types, parameter_types, traits::{ConstU32, Contains, Equals, Everything, Nothing}, @@ -35,12 +36,11 @@ use parachains_common::{ }; use polkadot_parachain_primitives::primitives::Sibling; use snowbridge_core::DescribeHere; -use snowbridge_kusama_common::EthereumNetwork; use snowbridge_runtime_common::XcmExportFeeToSibling; use sp_core::{Get, H256}; use sp_runtime::traits::AccountIdConversion; use sp_std::marker::PhantomData; -use system_parachains_constants::TREASURY_PALLET_ID; +use system_parachains_constants::{kusama::snowbridge::EthereumNetwork, TREASURY_PALLET_ID}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, @@ -50,7 +50,7 @@ use xcm_builder::{ ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, - XcmFeeManagerFromComponents, XcmFeeToAccount, + XcmFeeToAccount, }; use xcm_executor::{traits::{FeeManager, FeeReason, FeeReason::Export, WithOriginFilter}, XcmExecutor}; @@ -152,9 +152,12 @@ impl Contains for SafeCallFilter { match call { RuntimeCall::System(frame_system::Call::set_storage { items }) if items.iter().all(|(k, _)| { - k.eq(&DeliveryRewardInBalance::key()) || // todo one or two slashes? - k.eq(&RequiredStakeForStakeAndSlash::key()) | - k.eq(&EthereumGatewayAddress::key()) + k.eq(&DeliveryRewardInBalance::key()) || + k.eq(&RequiredStakeForStakeAndSlash::key()) || + k.eq(&EthereumGatewayAddress::key()) || + // Allow resetting of Ethereum nonces in Rococo only. + k.starts_with(&snowbridge_pallet_inbound_queue::Nonce::::final_prefix()) || + k.starts_with(&snowbridge_pallet_outbound_queue::Nonce::::final_prefix()) }) => return true, _ => (), @@ -201,13 +204,20 @@ impl Contains for SafeCallFilter { crate::bridge_to_polkadot_config::WithBridgeHubPolkadotMessagesInstance, >::set_operating_mode { .. }) | RuntimeCall::EthereumBeaconClient( - snowbridge_ethereum_beacon_client::Call::force_checkpoint { .. } | - snowbridge_ethereum_beacon_client::Call::set_operating_mode { .. }, + snowbridge_pallet_ethereum_client::Call::force_checkpoint { .. } | + snowbridge_pallet_ethereum_client::Call::set_operating_mode { .. }, ) | RuntimeCall::EthereumInboundQueue( - snowbridge_inbound_queue::Call::set_operating_mode { .. }, + snowbridge_pallet_inbound_queue::Call::set_operating_mode { .. }, ) | RuntimeCall::EthereumOutboundQueue( - snowbridge_outbound_queue::Call::set_operating_mode { .. }, - ) | RuntimeCall::EthereumSystem(..) + snowbridge_pallet_outbound_queue::Call::set_operating_mode { .. }, + ) | RuntimeCall::EthereumSystem( + snowbridge_pallet_system::Call::upgrade { .. } | + snowbridge_pallet_system::Call::set_operating_mode { .. } | + snowbridge_pallet_system::Call::set_pricing_parameters { .. } | + snowbridge_pallet_system::Call::force_update_channel { .. } | + snowbridge_pallet_system::Call::force_transfer_native_from_agent { .. } | + snowbridge_pallet_system::Call::set_token_transfer_fees { .. }, + ) ) } } @@ -301,12 +311,12 @@ impl xcm_executor::Config for XcmConfig { Self::AssetTransactor, crate::EthereumOutboundQueue, >, - XcmFeeToAccount, // todo check if right + XcmFeeToAccount, ), >; type MessageExporter = ( ToBridgeHubPolkadotHaulBlobExporter, - crate::bridge_to_ethereum_config::SnowbridgeExporter + crate::bridge_to_ethereum_config::SnowbridgeExporter, ); type UniversalAliases = Nothing; type CallDispatcher = WithOriginFilter; @@ -384,22 +394,3 @@ for XcmFeeManagerFromComponentsBridgeHub FeeHandler::handle_fee(fee, context, reason); } } - -#[cfg(feature = "runtime-benchmarks")] -pub mod benchmark_helpers { - use crate::{MultiAssets, MultiLocation, SendError, SendResult, SendXcm, Xcm, XcmHash}; - - pub struct DoNothingRouter; - impl SendXcm for DoNothingRouter { - type Ticket = (); - fn validate( - _dest: &mut Option, - _msg: &mut Option>, - ) -> SendResult<()> { - Ok(((), MultiAssets::new())) - } - fn deliver(_: ()) -> Result { - Ok([0; 32]) - } - } -} diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml index 09fbe3a36f..dd0e0c4e2f 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -109,6 +109,7 @@ bp-relayers = { default-features = false , version = "0.4.0" } bp-runtime = { default-features = false , version = "0.4.0" } bp-kusama = { default-features = false , version = "0.2.0" } bp-polkadot = { default-features = false , version = "0.2.0" } +bridge-hub-common = { default-features = false , version = "0.4.0" } #todo publish bridge-runtime-common = { default-features = false , version = "0.4.0" } pallet-bridge-grandpa = { default-features = false , version = "0.4.0" } pallet-bridge-messages = { default-features = false , version = "0.4.0" } @@ -120,13 +121,12 @@ snowbridge-beacon-primitives = { default-features = false , version = "1.0.0" } snowbridge-system = { default-features = false , version = "1.0.0" } snowbridge-system-runtime-api = { default-features = false , version = "1.0.0" } snowbridge-core = { default-features = false , version = "1.0.0" } -snowbridge-ethereum-beacon-client = { default-features = false , version = "1.0.0" } -snowbridge-inbound-queue = { default-features = false , version = "1.0.0" } -snowbridge-outbound-queue = { default-features = false , version = "1.0.0" } +snowbridge-pallet-ethereum-client = { default-features = false , version = "1.0.0" } +snowbridge-pallet-inbound-queue = { default-features = false , version = "1.0.0" } +snowbridge-pallet-outbound-queue = { default-features = false , version = "1.0.0" } snowbridge-outbound-queue-runtime-api = { default-features = false , version = "1.0.0" } snowbridge-router-primitives = { default-features = false , version = "1.0.0" } snowbridge-runtime-common = { default-features = false , version = "1.0.0" } -snowbridge-kusama-common = { default-features = false , version = "1.0.0" } [dev-dependencies] bridge-hub-test-utils = { version = "0.6.0" } diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/bridge_to_ethereum_config.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/bridge_to_ethereum_config.rs index 713af64649..f69f1d7dc6 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/bridge_to_ethereum_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/bridge_to_ethereum_config.rs @@ -18,7 +18,7 @@ use crate::{ xcm_config::UniversalLocation, Runtime, }; -use snowbridge_polkadot_common::EthereumNetwork; +use system_parachains_constants::polkadot::snowbridge::EthereumNetwork; use snowbridge_router_primitives::outbound::EthereumBlobExporter; /// Exports message to the Ethereum Gateway contract. diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs index ec566e4d77..6b8d795ef1 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -48,12 +48,6 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; -#[cfg(not(feature = "runtime-benchmarks"))] -use bridge_hub_common::BridgeHubMessageRouter; -use bridge_hub_common::{ - message_queue::{NarrowOriginToSibling, ParaIdToSibling}, - AggregateMessageOrigin, -}; use cumulus_primitives_core::ParaId; use frame_support::{ construct_runtime, @@ -91,6 +85,8 @@ use parachains_common::{ impls::DealWithFees, message_queue::*, AccountId, Balance, BlockNumber, Hash, Header, Nonce, Signature, }; + +use polkadot_runtime_common::prod_or_fast; use system_parachains_constants::{ polkadot::{consensus::*, currency::*, fee::WeightToFee}, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, @@ -99,17 +95,9 @@ use system_parachains_constants::{ use xcm::prelude::*; #[cfg(feature = "runtime-benchmarks")] -use crate::xcm_config::benchmark_helpers::DoNothingRouter; -#[cfg(feature = "runtime-benchmarks")] -use snowbridge_beacon_primitives::CompactExecutionHeader; -#[cfg(feature = "runtime-benchmarks")] -use snowbridge_core::RingBufferMap; -#[cfg(feature = "runtime-benchmarks")] -pub use snowbridge_ethereum_beacon_client::ExecutionHeaderBuffer; -#[cfg(feature = "runtime-benchmarks")] -use snowbridge_inbound_queue::BenchmarkHelper; -#[cfg(feature = "runtime-benchmarks")] -use sp_core::H256; +use benchmark_helpers::DoNothingRouter; +#[cfg(not(feature = "runtime-benchmarks"))] +use bridge_hub_common::BridgeHubMessageRouter; /// The address format for describing accounts. pub type Address = MultiAddress; @@ -155,6 +143,11 @@ pub type UncheckedExtrinsic = pub type Migrations = ( // unreleased cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, + snowbridge_pallet_system::migration::v0::InitializeOnUpgrade< + Runtime, + ConstU32, + ConstU32, + >, ); /// Executive: handles dispatch to the various modules. @@ -344,21 +337,27 @@ impl cumulus_pallet_parachain_system::Config for Runtime { impl parachain_info::Config for Runtime {} parameter_types! { - pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block; + /// Amount of weight that can be spent per block to service messages. This was increased + /// from 35% to 60% of the max block weight to accommodate the Ethereum beacon light client + /// extrinsics. The force_checkpoint and submit extrinsics (for submit, optionally) includes + /// the sync committee's pubkeys (512 x 48 bytes) + pub MessageQueueServiceWeight: Weight = Perbill::from_percent(60) * RuntimeBlockWeights::get().max_block; } impl pallet_message_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::pallet_message_queue::WeightInfo; #[cfg(feature = "runtime-benchmarks")] - type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor< - cumulus_primitives_core::AggregateMessageOrigin, - >; + type MessageProcessor = + pallet_message_queue::mock_helpers::NoopMessageProcessor; #[cfg(not(feature = "runtime-benchmarks"))] - type MessageProcessor = xcm_builder::ProcessXcmMessage< - AggregateMessageOrigin, - xcm_executor::XcmExecutor, - RuntimeCall, + type MessageProcessor = BridgeHubMessageRouter< + xcm_builder::ProcessXcmMessage< + AggregateMessageOrigin, + xcm_executor::XcmExecutor, + RuntimeCall, + >, + EthereumOutboundQueue, >; type Size = u32; // The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin: @@ -371,8 +370,6 @@ impl pallet_message_queue::Config for Runtime { impl cumulus_pallet_aura_ext::Config for Runtime {} -// todo add message queue pallet config impl pallet_message_queue::Config for Runtime { - parameter_types! { // Fellows pluralistic body. pub const FellowsBodyId: BodyId = BodyId::Technical; @@ -501,13 +498,6 @@ impl pallet_utility::Config for Runtime { } // Ethereum Bridge - -#[cfg(not(feature = "runtime-benchmarks"))] -parameter_types! { - pub storage EthereumGatewayAddress: H160 = H160::zero(); -} - -#[cfg(feature = "runtime-benchmarks")] parameter_types! { pub storage EthereumGatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39")); } @@ -515,7 +505,7 @@ parameter_types! { parameter_types! { pub const CreateAssetCall: [u8;2] = [53, 0]; pub const CreateAssetDeposit: u128 = (UNITS / 10) + EXISTENTIAL_DEPOSIT; - pub const InboundQueuePalletInstance: u8 = snowbridge_kusama_common::INBOUND_QUEUE_MESSAGES_PALLET_INDEX; + pub const InboundQueuePalletInstance: u8 = system_parachains_constants::polkadot::snowbridge::INBOUND_QUEUE_MESSAGES_PALLET_INDEX; pub Parameters: PricingParameters = PricingParameters { exchange_rate: FixedU128::from_rational(1, 400), fee_per_gas: gwei(20), @@ -524,15 +514,46 @@ parameter_types! { } #[cfg(feature = "runtime-benchmarks")] -impl BenchmarkHelper for Runtime { - fn initialize_storage(block_hash: H256, header: CompactExecutionHeader) { - >::insert(block_hash, header); +pub mod benchmark_helpers { + use crate::{EthereumBeaconClient, Runtime, RuntimeOrigin}; + use codec::Encode; + use snowbridge_beacon_primitives::CompactExecutionHeader; + use snowbridge_pallet_inbound_queue::BenchmarkHelper; + use sp_core::H256; + use xcm::latest::{Assets, Location, SendError, SendResult, SendXcm, Xcm, XcmHash}; + + impl BenchmarkHelper for Runtime { + fn initialize_storage(block_hash: H256, header: CompactExecutionHeader) { + EthereumBeaconClient::store_execution_header(block_hash, header, 0, H256::default()) + } + } + + pub struct DoNothingRouter; + impl SendXcm for DoNothingRouter { + type Ticket = Xcm<()>; + + fn validate( + _dest: &mut Option, + xcm: &mut Option>, + ) -> SendResult { + Ok((xcm.clone().unwrap(), Assets::new())) + } + fn deliver(xcm: Xcm<()>) -> Result { + let hash = xcm.using_encoded(sp_io::hashing::blake2_256); + Ok(hash) + } + } + + impl snowbridge_pallet_system::BenchmarkHelper for () { + fn make_xcm_origin(location: Location) -> RuntimeOrigin { + RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location)) + } } } -impl snowbridge_inbound_queue::Config for Runtime { +impl snowbridge_pallet_inbound_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type Verifier = snowbridge_ethereum_beacon_client::Pallet; + type Verifier = snowbridge_pallet_ethereum_client::Pallet; type Token = Balances; #[cfg(not(feature = "runtime-benchmarks"))] type XcmSender = XcmRouter; @@ -552,49 +573,53 @@ impl snowbridge_inbound_queue::Config for Runtime { type WeightToFee = WeightToFee; type LengthToFee = ConstantMultiplier; type MaxMessageSize = ConstU32<2048>; - type WeightInfo = weights::snowbridge_inbound_queue::WeightInfo; + type WeightInfo = weights::snowbridge_pallet_inbound_queue::WeightInfo; type PricingParameters = EthereumSystem; + type AssetTransactor = ::AssetTransactor; } -impl snowbridge_outbound_queue::Config for Runtime { +impl snowbridge_pallet_outbound_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Hashing = Keccak256; type MessageQueue = MessageQueue; - type Decimals = ConstU8<12>; + type Decimals = ConstU8<10>; type MaxMessagePayloadSize = ConstU32<2048>; type MaxMessagesPerBlock = ConstU32<32>; type GasMeter = snowbridge_core::outbound::ConstantGasMeter; type Balance = Balance; type WeightToFee = WeightToFee; - type WeightInfo = weights::snowbridge_outbound_queue::WeightInfo; + type WeightInfo = weights::snowbridge_pallet_outbound_queue::WeightInfo; type PricingParameters = EthereumSystem; type Channels = EthereumSystem; } -#[cfg(not(feature = "beacon-spec-mainnet"))] +#[cfg(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test))] parameter_types! { pub const ChainForkVersions: ForkVersions = ForkVersions { genesis: Fork { - version: [0, 0, 0, 1], // 0x00000001 + version: [0, 0, 0, 0], // 0x00000000 epoch: 0, }, altair: Fork { - version: [1, 0, 0, 1], // 0x01000001 + version: [1, 0, 0, 0], // 0x01000000 epoch: 0, }, bellatrix: Fork { - version: [2, 0, 0, 1], // 0x02000001 + version: [2, 0, 0, 0], // 0x02000000 epoch: 0, }, capella: Fork { - version: [3, 0, 0, 1], // 0x03000001 + version: [3, 0, 0, 0], // 0x03000000 epoch: 0, }, + deneb: Fork { + version: [4, 0, 0, 0], // 0x04000000 + epoch: 0, + } }; - pub const MaxExecutionHeadersToKeep:u32 = 1000; } -#[cfg(feature = "beacon-spec-mainnet")] +#[cfg(not(any(feature = "std", feature = "fast-runtime", feature = "runtime-benchmarks", test)))] parameter_types! { pub const ChainForkVersions: ForkVersions = ForkVersions { genesis: Fork { @@ -613,32 +638,32 @@ parameter_types! { version: [3, 0, 0, 0], // 0x03000000 epoch: 194048, }, + deneb: Fork { + version: [4, 0, 0, 0], // 0x04000000 + epoch: 99999999, // TODO update when epoch becomes known + }, }; - pub const MaxExecutionHeadersToKeep:u32 = 8192 * 2; } -impl snowbridge_ethereum_beacon_client::Config for Runtime { +parameter_types! { + pub const MaxExecutionHeadersToKeep: u32 = prod_or_fast!(8192 * 2, 1000); +} + +impl snowbridge_pallet_ethereum_client::Config for Runtime { type RuntimeEvent = RuntimeEvent; type ForkVersions = ChainForkVersions; type MaxExecutionHeadersToKeep = MaxExecutionHeadersToKeep; - type WeightInfo = weights::snowbridge_ethereum_beacon_client::WeightInfo; + type WeightInfo = weights::snowbridge_pallet_ethereum_client::WeightInfo; } -#[cfg(feature = "runtime-benchmarks")] -impl snowbridge_system::BenchmarkHelper for () { - fn make_xcm_origin(location: xcm::latest::MultiLocation) -> RuntimeOrigin { - RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location)) - } -} - -impl snowbridge_system::Config for Runtime { +impl snowbridge_pallet_system::Config for Runtime { type RuntimeEvent = RuntimeEvent; type OutboundQueue = EthereumOutboundQueue; type SiblingOrigin = EnsureXcm; type AgentIdOf = snowbridge_core::AgentIdOf; type TreasuryAccount = TreasuryAccount; type Token = Balances; - type WeightInfo = weights::snowbridge_system::WeightInfo; + type WeightInfo = weights::snowbridge_pallet_system::WeightInfo; #[cfg(feature = "runtime-benchmarks")] type Helper = (); type DefaultPricingParameters = Parameters; @@ -686,10 +711,13 @@ construct_runtime!( BridgeKusamaMessages: pallet_bridge_messages:: = 53, XcmOverBridgeHubKusama: pallet_xcm_bridge_hub:: = 54, - EthereumInboundQueue: snowbridge_inbound_queue = 80, - EthereumOutboundQueue: snowbridge_outbound_queue = 81, - EthereumBeaconClient: snowbridge_ethereum_beacon_client = 82, - EthereumSystem: snowbridge_system = 83, + // Ethereum bridge pallets. + EthereumInboundQueue: snowbridge_pallet_inbound_queue = 80, + EthereumOutboundQueue: snowbridge_pallet_inbound_queue = 81, + EthereumBeaconClient: snowbridge_pallet_ethereum_client = 82, + EthereumSystem: snowbridge_pallet_system = 83, + + // todo add message queue pallet here } ); @@ -719,10 +747,10 @@ mod benches { [pallet_bridge_parachains, KusamaParachains] [pallet_bridge_messages, KusamaMessages] // Ethereum Bridge - [snowbridge_inbound_queue, EthereumInboundQueue] - [snowbridge_outbound_queue, EthereumOutboundQueue] - [snowbridge_system, EthereumSystem] - [snowbridge_ethereum_beacon_client, EthereumBeaconClient] + [snowbridge_pallet_inbound_queue, EthereumInboundQueue] + [snowbridge_pallet_outbound_queue, EthereumOutboundQueue] + [snowbridge_pallet_system, EthereumSystem] + [snowbridge_pallet_ethereum_client, EthereumBeaconClient] ); } @@ -925,18 +953,18 @@ impl_runtime_apis! { } impl snowbridge_outbound_queue_runtime_api::OutboundQueueApi for Runtime { - fn prove_message(leaf_index: u64) -> Option { - snowbridge_outbound_queue::api::prove_message::(leaf_index) + fn prove_message(leaf_index: u64) -> Option { + snowbridge_pallet_outbound_queue::api::prove_message::(leaf_index) } fn calculate_fee(message: Message) -> Option { - snowbridge_outbound_queue::api::calculate_fee::(message) + snowbridge_pallet_outbound_queue::api::calculate_fee::(message) } } impl snowbridge_system_runtime_api::ControlApi for Runtime { - fn agent_id(location: VersionedMultiLocation) -> Option { - snowbridge_system::api::agent_id::(location) + fn agent_id(location: VersionedLocation) -> Option { + snowbridge_pallet_system::api::agent_id::(location) } } diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs index a9888646dd..72f74817a4 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/xcm_config.rs @@ -22,6 +22,7 @@ use super::{ PriceForParentDelivery, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, }; +use crate::EthereumGatewayAddress; use frame_support::{ match_types, parameter_types, traits::{ConstU32, Contains, Equals, Everything, Nothing}, @@ -35,11 +36,10 @@ use parachains_common::{ use polkadot_parachain_primitives::primitives::Sibling; use polkadot_runtime_constants::system_parachain; use snowbridge_core::DescribeHere; -use snowbridge_polkadot_common::EthereumNetwork; use snowbridge_runtime_common::XcmExportFeeToSibling; use sp_core::{Get, H256}; use sp_runtime::traits::AccountIdConversion; -use system_parachains_constants::TREASURY_PALLET_ID; +use system_parachains_constants::{polkadot::snowbridge::EthereumNetwork, TREASURY_PALLET_ID}; use sp_std::marker::PhantomData; use xcm::latest::prelude::*; use xcm_builder::{ @@ -50,7 +50,7 @@ use xcm_builder::{ ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, - XcmFeeManagerFromComponents, XcmFeeToAccount, + XcmFeeToAccount, }; use xcm_executor::{traits::{FeeManager, FeeReason, FeeReason::Export, WithOriginFilter}, XcmExecutor}; @@ -155,9 +155,12 @@ impl Contains for SafeCallFilter { match call { RuntimeCall::System(frame_system::Call::set_storage { items }) if items.iter().all(|(k, _)| { - k.eq(&DeliveryRewardInBalance::key()) || // todo one or two slashes? - k.eq(&RequiredStakeForStakeAndSlash::key()) | - k.eq(&EthereumGatewayAddress::key()) + k.eq(&DeliveryRewardInBalance::key()) || + k.eq(&RequiredStakeForStakeAndSlash::key()) || + k.eq(&EthereumGatewayAddress::key()) || + // Allow resetting of Ethereum nonces in Rococo only. + k.starts_with(&snowbridge_pallet_inbound_queue::Nonce::::final_prefix()) || + k.starts_with(&snowbridge_pallet_outbound_queue::Nonce::::final_prefix()) }) => return true, _ => (), @@ -204,13 +207,20 @@ impl Contains for SafeCallFilter { crate::bridge_to_kusama_config::WithBridgeHubKusamaMessagesInstance, >::set_operating_mode { .. }) | RuntimeCall::EthereumBeaconClient( - snowbridge_ethereum_beacon_client::Call::force_checkpoint { .. } | - snowbridge_ethereum_beacon_client::Call::set_operating_mode { .. }, + snowbridge_pallet_ethereum_client::Call::force_checkpoint { .. } | + snowbridge_pallet_ethereum_client::Call::set_operating_mode { .. }, ) | RuntimeCall::EthereumInboundQueue( - snowbridge_inbound_queue::Call::set_operating_mode { .. }, + snowbridge_pallet_inbound_queue::Call::set_operating_mode { .. }, ) | RuntimeCall::EthereumOutboundQueue( - snowbridge_outbound_queue::Call::set_operating_mode { .. }, - ) | RuntimeCall::EthereumSystem(..) + snowbridge_pallet_outbound_queue::Call::set_operating_mode { .. }, + ) | RuntimeCall::EthereumSystem( + snowbridge_pallet_system::Call::upgrade { .. } | + snowbridge_pallet_system::Call::set_operating_mode { .. } | + snowbridge_pallet_system::Call::set_pricing_parameters { .. } | + snowbridge_pallet_system::Call::force_update_channel { .. } | + snowbridge_pallet_system::Call::force_transfer_native_from_agent { .. } | + snowbridge_pallet_system::Call::set_token_transfer_fees { .. }, + ) ) } } @@ -308,7 +318,7 @@ impl xcm_executor::Config for XcmConfig { Self::AssetTransactor, crate::EthereumOutboundQueue, >, - XcmFeeToAccount, // todo check if right + XcmFeeToAccount, ), >; type MessageExporter = ( @@ -391,22 +401,3 @@ for XcmFeeManagerFromComponentsBridgeHub FeeHandler::handle_fee(fee, context, reason); } } - -#[cfg(feature = "runtime-benchmarks")] -pub mod benchmark_helpers { - use crate::{MultiAssets, MultiLocation, SendError, SendResult, SendXcm, Xcm, XcmHash}; - - pub struct DoNothingRouter; - impl SendXcm for DoNothingRouter { - type Ticket = (); - fn validate( - _dest: &mut Option, - _msg: &mut Option>, - ) -> SendResult<()> { - Ok(((), MultiAssets::new())) - } - fn deliver(_: ()) -> Result { - Ok([0; 32]) - } - } -}