Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AggregateMessageOrigin #1024

Merged
merged 11 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions parachain/Cargo.lock

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

6 changes: 3 additions & 3 deletions parachain/pallets/outbound-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -55,13 +55,13 @@ 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",
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"hex-literal",
"cumulus-primitives-core/runtime-benchmarks"
"bridge-hub-common/runtime-benchmarks",
]
4 changes: 2 additions & 2 deletions parachain/pallets/outbound-queue/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
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},
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion parachain/pallets/outbound-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions parachain/pallets/outbound-queue/src/send_message_impl.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -71,7 +71,7 @@ where
}

fn deliver(ticket: Self::Ticket) -> Result<H256, SendError> {
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);
Expand Down
17 changes: 9 additions & 8 deletions parachain/pallets/outbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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!(
Expand Down Expand Up @@ -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::<Test>();
Expand All @@ -212,29 +213,29 @@ 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
ServiceWeight::set(Some(Weight::MAX));
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);
});
}
3 changes: 3 additions & 0 deletions parachain/runtime/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions parachain/runtime/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<u8>| {
match RuntimeEvent::decode(&mut &runtime_event_encoded[..]) {
Ok(RuntimeEvent::EthereumOutboundQueue(event)) => Some(event),
Expand Down Expand Up @@ -69,6 +70,6 @@ pub fn transfer_token_to_ethereum_insufficient_fund() {
1000,
H160::random(),
H160::random(),
BridgeHubEthereumBaseFeeInRocs::get(),
BridgeHubEthereumBaseFeeInROC::get(),
)
}
6 changes: 3 additions & 3 deletions parachain/runtime/tests/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -131,7 +131,7 @@ pub fn send_transfer_token_message_success<Runtime, XcmConfig>(
// fund asset hub sovereign account enough so it can pay fees
initial_fund::<Runtime>(
assethub_parachain_id,
BridgeHubEthereumBaseFeeInRocs::get() + 1_000_000_000,
BridgeHubEthereumBaseFeeInROC::get() + 1_000_000_000,
);

let outcome = send_transfer_token_message::<Runtime, XcmConfig>(
Expand Down Expand Up @@ -269,7 +269,7 @@ pub fn send_transfer_token_message_fee_not_enough<Runtime, XcmConfig>(
// fund asset hub sovereign account enough so it can pay fees
initial_fund::<Runtime>(
assethub_parachain_id,
BridgeHubEthereumBaseFeeInRocs::get() + 1_000_000_000,
BridgeHubEthereumBaseFeeInROC::get() + 1_000_000_000,
);

let outcome = send_transfer_token_message::<Runtime, XcmConfig>(
Expand Down
2 changes: 1 addition & 1 deletion polkadot-sdk
Submodule polkadot-sdk updated 20 files
+7 −1 Cargo.lock
+0 −1 cumulus/parachains/common/src/lib.rs
+0 −9 cumulus/parachains/common/src/snowbridge_config.rs
+1 −0 cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/Cargo.toml
+1 −1 cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/lib.rs
+1 −0 cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/Cargo.toml
+1 −1 cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/lib.rs
+2 −0 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/Cargo.toml
+7 −5 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/lib.rs
+24 −11 cumulus/parachains/integration-tests/emulated/tests/bridges/bridge-hub-rococo/src/tests/snowbridge.rs
+6 −2 cumulus/parachains/runtimes/assets/asset-hub-rococo/src/xcm_config.rs
+5 −2 cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs
+3 −0 cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml
+5 −2 cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs
+5 −2 cumulus/parachains/runtimes/bridge-hubs/common/Cargo.toml
+1 −1 cumulus/parachains/runtimes/bridge-hubs/common/src/lib.rs
+96 −5 cumulus/parachains/runtimes/bridge-hubs/common/src/message_queue.rs
+0 −1 cumulus/parachains/runtimes/testing/penpal/src/lib.rs
+0 −7 cumulus/primitives/core/src/lib.rs
+11 −7 cumulus/xcm/xcm-emulator/src/lib.rs
Loading