From d0add92bdf9cfb676b2aeb95afca76c0bd865daa Mon Sep 17 00:00:00 2001 From: Vincent Geddes Date: Thu, 1 Jun 2023 06:53:17 +0200 Subject: [PATCH 1/2] Add MessageQueue pallet to BridgeHub --- .../bridge-hubs/bridge-hub-rococo/Cargo.toml | 4 +++ .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 27 ++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 86383d30d99..f62c67dd362 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -28,6 +28,7 @@ pallet-aura = { git = "https://github.com/paritytech/substrate", default-feature pallet-authorship = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +pallet-message-queue = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } @@ -139,6 +140,7 @@ std = [ "pallet-bridge-parachains/std", "pallet-bridge-relayers/std", "pallet-collator-selection/std", + "pallet-message-queue/std", "pallet-multisig/std", "pallet-session/std", "pallet-timestamp/std", @@ -188,6 +190,7 @@ runtime-benchmarks = [ "pallet-bridge-parachains/runtime-benchmarks", "pallet-bridge-relayers/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", + "pallet-message-queue/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", @@ -221,6 +224,7 @@ try-runtime = [ "pallet-authorship/try-runtime", "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", + "pallet-message-queue/try-runtime", "pallet-multisig/try-runtime", "pallet-session/try-runtime", "pallet-timestamp/try-runtime", diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index f741d17aecd..c473659537e 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -400,6 +400,24 @@ impl pallet_utility::Config for Runtime { type WeightInfo = weights::pallet_utility::WeightInfo; } +parameter_types! { + /// Amount of weight that can be spent per block to service messages. + pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000); + pub const MessageQueueHeapSize: u32 = 65_536; + pub const MessageQueueMaxStale: u32 = 16; +} + +impl pallet_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Size = u32; + type HeapSize = MessageQueueHeapSize; + type MaxStale = MessageQueueMaxStale; + type ServiceWeight = MessageQueueServiceWeight; + type MessageProcessor = EthereumOutboundQueue; + type QueueChangeHandler = (); + type WeightInfo = (); +} + // Add bridge pallets (GPA) /// Add GRANDPA bridge pallet to track Wococo relay chain on Rococo BridgeHub @@ -571,14 +589,15 @@ impl snowbridge_inbound_queue::Config for Runtime { parameter_types! { pub const MaxMessagePayloadSize: u32 = 256; - pub const MaxMessagesPerCommit: u32 = 20; + pub const MaxMessagesPerBlock: u32 = 32; } impl snowbridge_outbound_queue::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Hashing = Keccak256; + type MessageQueue = MessageQueue; type MaxMessagePayloadSize = MaxMessagePayloadSize; - type MaxMessagesPerCommit = MaxMessagesPerCommit; + type MaxMessagesPerBlock = MaxMessagesPerBlock; type WeightInfo = (); } @@ -670,6 +689,7 @@ construct_runtime!( // Handy utilities. Utility: pallet_utility::{Pallet, Call, Event} = 40, Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 36, + MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event} = 37, // Rococo and Wococo Bridge Hubs are sharing the runtime, so this runtime has two sets of // bridge pallets. Both are deployed at both runtimes, but only one set is actually used @@ -689,7 +709,7 @@ construct_runtime!( // Ethereum Bridge EthereumInboundQueue: snowbridge_inbound_queue::{Pallet, Call, Config, Storage, Event} = 48, - EthereumOutboundQueue: snowbridge_outbound_queue::{Pallet, Config, Storage, Event} = 49, + EthereumOutboundQueue: snowbridge_outbound_queue::{Pallet, Storage, Event} = 49, EthereumBeaconClient: snowbridge_ethereum_beacon_client::{Pallet, Call, Storage, Event} = 50, } ); @@ -714,6 +734,7 @@ mod benches { [frame_system, SystemBench::] [pallet_balances, Balances] [pallet_multisig, Multisig] + [pallet_message_queue, MessageQueue] [pallet_session, SessionBench::] [pallet_utility, Utility] [pallet_timestamp, Timestamp] From c68d00ef896e895e46fab53ce845c4f9a7bfa949 Mon Sep 17 00:00:00 2001 From: Vincent Geddes Date: Wed, 14 Jun 2023 21:25:27 +0200 Subject: [PATCH 2/2] update --- Cargo.lock | 40 ++++++++++++++----- .../bridge-hubs/bridge-hub-rococo/Cargo.toml | 9 ++++- .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 28 +++++++++++-- .../bridge-hub-rococo/src/xcm_config.rs | 5 +-- polkadot-parachain/Cargo.toml | 3 -- .../src/chain_spec/bridge_hubs.rs | 3 -- polkadot-parachain/src/rpc.rs | 8 ---- 7 files changed, 64 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1b3bfd30455..eaeff6a4fd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1116,6 +1116,7 @@ dependencies = [ "pallet-bridge-parachains", "pallet-bridge-relayers", "pallet-collator-selection", + "pallet-message-queue", "pallet-multisig", "pallet-session", "pallet-timestamp", @@ -1135,10 +1136,12 @@ dependencies = [ "serde", "smallvec", "snowbridge-beacon-primitives", + "snowbridge-control", "snowbridge-core", "snowbridge-ethereum-beacon-client", "snowbridge-inbound-queue", "snowbridge-outbound-queue", + "snowbridge-outbound-queue-runtime-api", "snowbridge-router-primitives", "sp-api", "sp-block-builder", @@ -9497,7 +9500,6 @@ dependencies = [ "serde", "serde_json", "shell-runtime", - "snowbridge-outbound-queue-rpc", "sp-api", "sp-block-builder", "sp-blockchain", @@ -12832,6 +12834,24 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "snowbridge-control" +version = "4.0.0-dev" +dependencies = [ + "ethabi-decode", + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "snowbridge-core", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "xcm", +] + [[package]] name = "snowbridge-core" version = "0.1.1" @@ -12846,6 +12866,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-std", + "xcm", ] [[package]] @@ -12931,33 +12952,33 @@ dependencies = [ "scale-info", "serde", "snowbridge-core", - "snowbridge-outbound-queue-merkle-proof", + "snowbridge-outbound-queue-merkle-tree", "sp-core", "sp-io", "sp-runtime", "sp-std", + "xcm", ] [[package]] -name = "snowbridge-outbound-queue-merkle-proof" +name = "snowbridge-outbound-queue-merkle-tree" version = "0.1.1" dependencies = [ "parity-scale-codec", + "scale-info", "sp-core", "sp-runtime", ] [[package]] -name = "snowbridge-outbound-queue-rpc" +name = "snowbridge-outbound-queue-runtime-api" version = "0.1.0" dependencies = [ - "jsonrpsee", "parity-scale-codec", - "parking_lot 0.11.2", - "snowbridge-outbound-queue-merkle-proof", + "snowbridge-outbound-queue-merkle-tree", + "sp-api", "sp-core", - "sp-offchain", - "sp-runtime", + "sp-std", ] [[package]] @@ -12967,6 +12988,7 @@ dependencies = [ "ethabi-decode", "frame-support", "frame-system", + "hex-literal 0.4.1", "parity-scale-codec", "scale-info", "serde", diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 8b4dbb1d374..b200b6fd147 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -90,11 +90,14 @@ bridge-runtime-common = { path = "../../../../bridges/bin/runtime-common", defau # Ethereum Bridge (Snowbridge) snowbridge-core = { path = "../../../../../parachain/primitives/core", default-features = false } -snowbridge-beacon-primitives = { path = "../../../../../parachain/primitives/beacon", default-features = false } snowbridge-router-primitives = { path = "../../../../../parachain/primitives/router", default-features = false } +snowbridge-beacon-primitives = { path = "../../../../../parachain/primitives/beacon", default-features = false } snowbridge-inbound-queue = { path = "../../../../../parachain/pallets/inbound-queue", default-features = false } snowbridge-outbound-queue = { path = "../../../../../parachain/pallets/outbound-queue", default-features = false } +snowbridge-outbound-queue-runtime-api = { path = "../../../../../parachain/pallets/outbound-queue/runtime-api", default-features = false } snowbridge-ethereum-beacon-client = { path = "../../../../../parachain/pallets/ethereum-beacon-client", default-features = false } +snowbridge-control = { path = "../../../../../parachain/pallets/control", default-features = false } + [dev-dependencies] static_assertions = "1.1" @@ -172,11 +175,13 @@ std = [ "xcm-executor/std", "xcm/std", "snowbridge-core/std", - "snowbridge-beacon-primitives/std", "snowbridge-router-primitives/std", + "snowbridge-beacon-primitives/std", "snowbridge-inbound-queue/std", "snowbridge-outbound-queue/std", + "snowbridge-outbound-queue-runtime-api/std", "snowbridge-ethereum-beacon-client/std", + "snowbridge-control/std", "substrate-wasm-builder", ] diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index d78896b5d68..67eb50a3752 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -566,8 +566,6 @@ impl pallet_bridge_relayers::Config for Runtime { // Ethereum Bridge -use snowbridge_router_primitives::InboundMessageConverter; - parameter_types! { pub const EthereumNetwork: xcm::v3::NetworkId = xcm::v3::NetworkId::Ethereum { chain_id: 1 }; } @@ -581,7 +579,6 @@ impl snowbridge_inbound_queue::Config for Runtime { type Token = Balances; type Reward = Reward; type Verifier = snowbridge_ethereum_beacon_client::Pallet; - type MessageConversion = InboundMessageConverter; type XcmSender = XcmRouter; type WeightInfo = (); } @@ -653,6 +650,19 @@ impl snowbridge_ethereum_beacon_client::Config for Runtime { type WeightInfo = weights::snowbridge_ethereum_beacon_client::WeightInfo; } +parameter_types! { + pub const GovernanceProxyContract: snowbridge_core::ContractId = snowbridge_core::ContractId::new(hex_literal::hex!("44bef07c29162ad04096f5cbe78ca2df62dffe97cea85825f08d13319e13f34a")); +} + +impl snowbridge_control::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type OwnParaId = ParachainInfo; + type OutboundQueue = EthereumOutboundQueue; + type GovernanceProxyContract = GovernanceProxyContract; + type MessageHasher = BlakeTwo256; + type WeightInfo = (); +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -688,7 +698,6 @@ construct_runtime!( // Handy utilities. Utility: pallet_utility::{Pallet, Call, Event} = 40, Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 36, - MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event} = 37, // Rococo and Wococo Bridge Hubs are sharing the runtime, so this runtime has two sets of // bridge pallets. Both are deployed at both runtimes, but only one set is actually used @@ -710,6 +719,11 @@ construct_runtime!( EthereumInboundQueue: snowbridge_inbound_queue::{Pallet, Call, Config, Storage, Event} = 48, EthereumOutboundQueue: snowbridge_outbound_queue::{Pallet, Storage, Event} = 49, EthereumBeaconClient: snowbridge_ethereum_beacon_client::{Pallet, Call, Storage, Event} = 50, + EthereumControl: snowbridge_control::{Pallet, Call, Storage, Event} = 51, + + // Message Queue. Registered after EthereumOutboundQueue so that their `on_initialize` handlers + // run in the desired order. + MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event} = 60, } ); @@ -966,6 +980,12 @@ 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) + } + } + #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { diff --git a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs index c01c34a3b38..39ec98fbfeb 100644 --- a/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs +++ b/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/xcm_config.rs @@ -22,8 +22,7 @@ use super::{ }; use crate::{ bridge_hub_rococo_config::ToBridgeHubWococoHaulBlobExporter, - bridge_hub_wococo_config::ToBridgeHubRococoHaulBlobExporter, - EthereumNetwork, + bridge_hub_wococo_config::ToBridgeHubRococoHaulBlobExporter, EthereumNetwork, }; use frame_support::{ match_types, parameter_types, @@ -34,7 +33,7 @@ use pallet_xcm::XcmPassthrough; use parachains_common::{impls::ToStakingPot, xcm_config::ConcreteNativeAssetFrom}; use polkadot_parachain::primitives::Sibling; use snowbridge_outbound_queue; -use snowbridge_router_primitives::export::EthereumBlobExporter; +use snowbridge_router_primitives::outbound::EthereumBlobExporter; use sp_core::Get; use xcm::latest::prelude::*; use xcm_builder::{ diff --git a/polkadot-parachain/Cargo.toml b/polkadot-parachain/Cargo.toml index d596cb6cdd8..21d0ebfe975 100644 --- a/polkadot-parachain/Cargo.toml +++ b/polkadot-parachain/Cargo.toml @@ -90,9 +90,6 @@ cumulus-primitives-parachain-inherent = { path = "../primitives/parachain-inhere cumulus-relay-chain-interface = { path = "../client/relay-chain-interface" } color-print = "0.3.4" -# Ethereum Bridge -snowbridge-outbound-queue-rpc = { path = "../../parachain/pallets/outbound-queue/rpc" } - [build-dependencies] substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/polkadot-parachain/src/chain_spec/bridge_hubs.rs index febb21b6647..51bd6e4924d 100644 --- a/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -346,9 +346,6 @@ pub mod rococo { ethereum_inbound_queue: bridge_hub_rococo_runtime::EthereumInboundQueueConfig { allowlist: Default::default(), }, - ethereum_outbound_queue: bridge_hub_rococo_runtime::EthereumOutboundQueueConfig { - interval: 1, - }, } } } diff --git a/polkadot-parachain/src/rpc.rs b/polkadot-parachain/src/rpc.rs index c0cc5cfc2cf..0ccd2f63223 100644 --- a/polkadot-parachain/src/rpc.rs +++ b/polkadot-parachain/src/rpc.rs @@ -63,7 +63,6 @@ where { use frame_rpc_system::{System, SystemApiServer}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; - use snowbridge_outbound_queue_rpc::{OutboundQueue, OutboundQueueApiServer}; use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer}; let mut module = RpcExtension::new(()); @@ -73,13 +72,6 @@ where module.merge(TransactionPayment::new(client.clone()).into_rpc())?; module.merge(StateMigration::new(client, backend.clone(), deny_unsafe).into_rpc())?; - if let Some(outbound_queue_rpc) = backend - .offchain_storage() - .map(|storage| OutboundQueue::::new(storage).into_rpc()) - { - module.merge(outbound_queue_rpc)?; - } - Ok(module) }