From 0120c601c14f1b96f4e94ca6392e21509c13ab76 Mon Sep 17 00:00:00 2001 From: Clara van Staden Date: Tue, 28 Nov 2023 12:05:32 +0200 Subject: [PATCH] Update AggregateMessageOrigin (#1024) * fmt * fix imports * fmt * Fix breaking tests * updates * update polkadot sdk * update polkadot-sdk.. again * fixes config * check if tests work * fix test * updates polkadot-sdk again again --------- Co-authored-by: claravanstaden Co-authored-by: ron --- parachain/Cargo.lock | 19 +++++++++++++++---- parachain/pallets/outbound-queue/Cargo.toml | 6 +++--- .../outbound-queue/src/benchmarking.rs | 4 ++-- parachain/pallets/outbound-queue/src/lib.rs | 2 +- .../outbound-queue/src/send_message_impl.rs | 4 ++-- parachain/pallets/outbound-queue/src/test.rs | 17 +++++++++-------- parachain/runtime/tests/Cargo.toml | 3 +++ parachain/runtime/tests/src/lib.rs | 7 ++++--- parachain/runtime/tests/src/test_cases.rs | 6 +++--- polkadot-sdk | 2 +- 10 files changed, 43 insertions(+), 27 deletions(-) diff --git a/parachain/Cargo.lock b/parachain/Cargo.lock index 926821846e..a6de042330 100644 --- a/parachain/Cargo.lock +++ b/parachain/Cargo.lock @@ -729,7 +729,6 @@ checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" dependencies = [ "funty", "radium", - "serde", "tap", "wyz", ] @@ -827,6 +826,20 @@ dependencies = [ "trie-db", ] +[[package]] +name = "bridge-hub-common" +version = "0.1.0" +dependencies = [ + "cumulus-primitives-core", + "frame-support", + "pallet-message-queue", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std 8.0.0", + "staging-xcm", +] + [[package]] name = "bs58" version = "0.5.0" @@ -1781,7 +1794,6 @@ name = "frame-system" version = "4.0.0-dev" dependencies = [ "cfg-if", - "docify", "frame-support", "log", "parity-scale-codec", @@ -2694,7 +2706,6 @@ dependencies = [ name = "pallet-message-queue" version = "7.0.0-dev" dependencies = [ - "environmental", "frame-benchmarking", "frame-support", "frame-system", @@ -3860,7 +3871,7 @@ dependencies = [ name = "snowbridge-outbound-queue" version = "0.1.1" dependencies = [ - "cumulus-primitives-core", + "bridge-hub-common", "ethabi-decode", "frame-benchmarking", "frame-support", diff --git a/parachain/pallets/outbound-queue/Cargo.toml b/parachain/pallets/outbound-queue/Cargo.toml index 2fdef01f1c..5706a955cb 100644 --- a/parachain/pallets/outbound-queue/Cargo.toml +++ b/parachain/pallets/outbound-queue/Cargo.toml @@ -24,7 +24,7 @@ sp-runtime = { path = "../../../polkadot-sdk/substrate/primitives/runtime", defa sp-io = { path = "../../../polkadot-sdk/substrate/primitives/io", default-features = false } sp-arithmetic = { path = "../../../polkadot-sdk/substrate/primitives/arithmetic", default-features = false } -cumulus-primitives-core = { path = "../../../polkadot-sdk/cumulus/primitives/core", default-features = false } +bridge-hub-common = { path = "../../../polkadot-sdk/cumulus/parachains/runtimes/bridge-hubs/common", default-features = false } snowbridge-core = { path = "../../primitives/core", features = ["serde"], default-features = false } snowbridge-outbound-queue-merkle-tree = { path = "merkle-tree", default-features = false } @@ -55,7 +55,7 @@ std = [ "snowbridge-outbound-queue-merkle-tree/std", "ethabi/std", "xcm/std", - "cumulus-primitives-core/std" + "bridge-hub-common/std", ] runtime-benchmarks = [ "snowbridge-core/runtime-benchmarks", @@ -63,5 +63,5 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "hex-literal", - "cumulus-primitives-core/runtime-benchmarks" + "bridge-hub-common/runtime-benchmarks", ] diff --git a/parachain/pallets/outbound-queue/src/benchmarking.rs b/parachain/pallets/outbound-queue/src/benchmarking.rs index 616737ef35..ee5754e869 100644 --- a/parachain/pallets/outbound-queue/src/benchmarking.rs +++ b/parachain/pallets/outbound-queue/src/benchmarking.rs @@ -2,8 +2,8 @@ // SPDX-FileCopyrightText: 2023 Snowfork use super::*; +use bridge_hub_common::AggregateMessageOrigin; use codec::Encode; -use cumulus_primitives_core::AggregateMessageOrigin; use frame_benchmarking::v2::*; use snowbridge_core::{ outbound::{Command, Initializer}, @@ -36,7 +36,7 @@ mod benchmarks { }), }, }; - let origin = AggregateMessageOrigin::GeneralKey([1; 32]); + let origin = AggregateMessageOrigin::Snowbridge([1; 32].into()); let encoded_enqueued_message = enqueued_message.encode(); #[block] diff --git a/parachain/pallets/outbound-queue/src/lib.rs b/parachain/pallets/outbound-queue/src/lib.rs index 0f65e4f193..b4f30e7fdb 100644 --- a/parachain/pallets/outbound-queue/src/lib.rs +++ b/parachain/pallets/outbound-queue/src/lib.rs @@ -95,8 +95,8 @@ mod mock; #[cfg(test)] mod test; +use bridge_hub_common::AggregateMessageOrigin; use codec::Decode; -use cumulus_primitives_core::AggregateMessageOrigin; use frame_support::{ storage::StorageStreamIter, traits::{tokens::Balance, EnqueueMessage, Get, ProcessMessageError}, diff --git a/parachain/pallets/outbound-queue/src/send_message_impl.rs b/parachain/pallets/outbound-queue/src/send_message_impl.rs index 16571e8fbb..813103485b 100644 --- a/parachain/pallets/outbound-queue/src/send_message_impl.rs +++ b/parachain/pallets/outbound-queue/src/send_message_impl.rs @@ -1,7 +1,7 @@ //! Implementation for [`snowbridge_core::outbound::SendMessage`] use super::*; +use bridge_hub_common::AggregateMessageOrigin; use codec::Encode; -use cumulus_primitives_core::AggregateMessageOrigin; use frame_support::{ ensure, traits::{EnqueueMessage, Get}, @@ -71,7 +71,7 @@ where } fn deliver(ticket: Self::Ticket) -> Result { - let origin = AggregateMessageOrigin::GeneralKey(ticket.channel_id.into()); + let origin = AggregateMessageOrigin::Snowbridge(ticket.channel_id); if ticket.channel_id != PRIMARY_GOVERNANCE_CHANNEL { ensure!(!Self::operating_mode().is_halted(), SendError::Halted); diff --git a/parachain/pallets/outbound-queue/src/test.rs b/parachain/pallets/outbound-queue/src/test.rs index 3dbcc9f8a9..dbf5ebbd4c 100644 --- a/parachain/pallets/outbound-queue/src/test.rs +++ b/parachain/pallets/outbound-queue/src/test.rs @@ -88,7 +88,7 @@ fn process_message_yields_on_max_messages_per_block() { } let channel_id: ChannelId = ParaId::from(1000).into(); - let origin = AggregateMessageOrigin::GeneralKey(channel_id.into()); + let origin = AggregateMessageOrigin::Snowbridge(channel_id.into()); let message = QueuedMessage { id: Default::default(), channel_id, @@ -114,7 +114,7 @@ fn process_message_fails_on_overweight_message() { new_tester().execute_with(|| { let sibling_id = 1000; let channel_id: ChannelId = ParaId::from(sibling_id).into(); - let origin = AggregateMessageOrigin::GeneralKey(channel_id.into()); + let origin = AggregateMessageOrigin::Snowbridge(channel_id.into()); let message = mock_message(sibling_id).encode(); let mut meter = WeightMeter::with_limit(Weight::from_parts(1, 1)); assert_noop!( @@ -200,7 +200,8 @@ fn governance_message_does_not_get_the_chance_to_processed_in_same_block_when_co let (ticket, _) = OutboundQueue::validate(&message).unwrap(); OutboundQueue::deliver(ticket).unwrap(); } - let footprint = MessageQueue::footprint(GeneralKey(sibling_channel_id.into())); + + let footprint = MessageQueue::footprint(Snowbridge(sibling_channel_id.into())); assert_eq!(footprint.storage.count, (max_messages) as u64); let message = mock_governance_message::(); @@ -212,11 +213,11 @@ fn governance_message_does_not_get_the_chance_to_processed_in_same_block_when_co run_to_end_of_next_block(); // first process 20 messages from sibling channel - let footprint = MessageQueue::footprint(GeneralKey(sibling_channel_id.into())); + let footprint = MessageQueue::footprint(Snowbridge(sibling_channel_id.into())); assert_eq!(footprint.storage.count, 40 - 20); // and governance message does not have the chance to execute in same block - let footprint = MessageQueue::footprint(GeneralKey(PRIMARY_GOVERNANCE_CHANNEL.into())); + let footprint = MessageQueue::footprint(Snowbridge(PRIMARY_GOVERNANCE_CHANNEL.into())); assert_eq!(footprint.storage.count, 1); // move to next block @@ -224,17 +225,17 @@ fn governance_message_does_not_get_the_chance_to_processed_in_same_block_when_co run_to_end_of_next_block(); // now governance message get executed in this block - let footprint = MessageQueue::footprint(GeneralKey(PRIMARY_GOVERNANCE_CHANNEL.into())); + let footprint = MessageQueue::footprint(Snowbridge(PRIMARY_GOVERNANCE_CHANNEL.into())); assert_eq!(footprint.storage.count, 0); // and this time process 19 messages from sibling channel so we have 1 message left - let footprint = MessageQueue::footprint(GeneralKey(sibling_channel_id.into())); + let footprint = MessageQueue::footprint(Snowbridge(sibling_channel_id.into())); assert_eq!(footprint.storage.count, 1); // move to the next block, the last 1 message from sibling channel get executed ServiceWeight::set(Some(Weight::MAX)); run_to_end_of_next_block(); - let footprint = MessageQueue::footprint(GeneralKey(sibling_channel_id.into())); + let footprint = MessageQueue::footprint(Snowbridge(sibling_channel_id.into())); assert_eq!(footprint.storage.count, 0); }); } diff --git a/parachain/runtime/tests/Cargo.toml b/parachain/runtime/tests/Cargo.toml index ede65f7b03..1615cb30dd 100644 --- a/parachain/runtime/tests/Cargo.toml +++ b/parachain/runtime/tests/Cargo.toml @@ -72,6 +72,7 @@ parachain-info = { package = "staging-parachain-info", path = "../../../polkadot parachains-common = { path = "../../../polkadot-sdk/cumulus/parachains/common", default-features = false } parachains-runtimes-test-utils = { path = "../../../polkadot-sdk/cumulus/parachains/runtimes/test-utils", default-features = false } bridge-hub-rococo-runtime = { path = "../../../polkadot-sdk/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo", default-features = false } +asset-hub-rococo-runtime = { path = "../../../polkadot-sdk/cumulus/parachains/runtimes/assets/asset-hub-rococo", default-features = false } assets-common = { path = "../../../polkadot-sdk/cumulus/parachains/runtimes/assets/common", default-features = false } # Ethereum Bridge (Snowbridge) @@ -104,6 +105,7 @@ std = [ "cumulus-primitives-core/std", "cumulus-primitives-utility/std", "bridge-hub-rococo-runtime/std", + "asset-hub-rococo-runtime/std", "assets-common/std", "parachains-runtimes-test-utils/std", "frame-benchmarking/std", @@ -169,6 +171,7 @@ runtime-benchmarks = [ "cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", "bridge-hub-rococo-runtime/runtime-benchmarks", + "asset-hub-rococo-runtime/runtime-benchmarks", "assets-common/runtime-benchmarks", "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", diff --git a/parachain/runtime/tests/src/lib.rs b/parachain/runtime/tests/src/lib.rs index 8b5e9b18b7..1132160feb 100644 --- a/parachain/runtime/tests/src/lib.rs +++ b/parachain/runtime/tests/src/lib.rs @@ -7,7 +7,8 @@ mod test_cases; use bridge_hub_rococo_runtime::{xcm_config::XcmConfig, Runtime, RuntimeEvent, SessionKeys}; use codec::Decode; -use parachains_common::{snowbridge_config::BridgeHubEthereumBaseFeeInRocs, AccountId, AuraId}; +use parachains_common::{AccountId, AuraId}; +use asset_hub_rococo_runtime::xcm_config::bridging::to_ethereum::BridgeHubEthereumBaseFeeInROC; use sp_core::H160; use sp_keyring::AccountKeyring::Alice; @@ -27,7 +28,7 @@ pub fn transfer_token_to_ethereum_works() { 1000, H160::random(), H160::random(), - BridgeHubEthereumBaseFeeInRocs::get(), + BridgeHubEthereumBaseFeeInROC::get(), Box::new(|runtime_event_encoded: Vec| { match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) { Ok(RuntimeEvent::EthereumOutboundQueue(event)) => Some(event), @@ -69,6 +70,6 @@ pub fn transfer_token_to_ethereum_insufficient_fund() { 1000, H160::random(), H160::random(), - BridgeHubEthereumBaseFeeInRocs::get(), + BridgeHubEthereumBaseFeeInROC::get(), ) } diff --git a/parachain/runtime/tests/src/test_cases.rs b/parachain/runtime/tests/src/test_cases.rs index 01a039902c..7bea8477ac 100644 --- a/parachain/runtime/tests/src/test_cases.rs +++ b/parachain/runtime/tests/src/test_cases.rs @@ -5,7 +5,7 @@ use codec::Encode; use frame_support::{assert_err, assert_ok, traits::fungible::Mutate}; -use parachains_common::snowbridge_config::BridgeHubEthereumBaseFeeInRocs; +use asset_hub_rococo_runtime::xcm_config::bridging::to_ethereum::BridgeHubEthereumBaseFeeInROC; use parachains_runtimes_test_utils::{ AccountIdOf, BalanceOf, CollatorSessionKeys, ExtBuilder, ValidatorIdOf, XcmReceivedFrom, }; @@ -131,7 +131,7 @@ pub fn send_transfer_token_message_success( // fund asset hub sovereign account enough so it can pay fees initial_fund::( assethub_parachain_id, - BridgeHubEthereumBaseFeeInRocs::get() + 1_000_000_000, + BridgeHubEthereumBaseFeeInROC::get() + 1_000_000_000, ); let outcome = send_transfer_token_message::( @@ -269,7 +269,7 @@ pub fn send_transfer_token_message_fee_not_enough( // fund asset hub sovereign account enough so it can pay fees initial_fund::( assethub_parachain_id, - BridgeHubEthereumBaseFeeInRocs::get() + 1_000_000_000, + BridgeHubEthereumBaseFeeInROC::get() + 1_000_000_000, ); let outcome = send_transfer_token_message::( diff --git a/polkadot-sdk b/polkadot-sdk index aa29476ec3..42537e8239 160000 --- a/polkadot-sdk +++ b/polkadot-sdk @@ -1 +1 @@ -Subproject commit aa29476ec3abb8c6e6f01f0a4d8b22bbc0333f95 +Subproject commit 42537e8239fbfc06be1511c211d9c0393fbd6d27