Skip to content

Commit

Permalink
fix westend config
Browse files Browse the repository at this point in the history
  • Loading branch information
claravanstaden committed Nov 25, 2024
1 parent 02e8081 commit ee0bc27
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 31 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

42 changes: 22 additions & 20 deletions bridges/snowbridge/primitives/router/src/inbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,30 @@ use sp_std::marker::PhantomData;
use xcm::prelude::{AccountKey20, Ethereum, GlobalConsensus, Location};
use xcm_executor::traits::ConvertLocation;

pub struct GlobalConsensusEthereumConvertsFor<AccountId>(PhantomData<AccountId>);
impl<AccountId> ConvertLocation<AccountId> for GlobalConsensusEthereumConvertsFor<AccountId>
where
AccountId: From<[u8; 32]> + Clone,
pub struct EthereumLocationsConverterFor<AccountId>(PhantomData<AccountId>);
impl<AccountId> ConvertLocation<AccountId> for EthereumLocationsConverterFor<AccountId>
where
AccountId: From<[u8; 32]> + Clone,
{
fn convert_location(location: &Location) -> Option<AccountId> {
match location.unpack() {
(2, [GlobalConsensus(Ethereum { chain_id })]) =>
Some(Self::from_chain_id(chain_id).into()),
(2, [GlobalConsensus(Ethereum { chain_id }), AccountKey20 { network: _, key }]) =>
Some(Self::from_chain_id_with_key(chain_id, *key).into()),
_ => None,
}
}
fn convert_location(location: &Location) -> Option<AccountId> {
match location.unpack() {
(2, [GlobalConsensus(Ethereum { chain_id })]) =>
Some(Self::from_chain_id(chain_id).into()),
(2, [GlobalConsensus(Ethereum { chain_id }), AccountKey20 { network: _, key }]) =>
Some(Self::from_chain_id_with_key(chain_id, *key).into()),
_ => None,
}
}
}
impl<AccountId> GlobalConsensusEthereumConvertsFor<AccountId> {
pub fn from_chain_id(chain_id: &u64) -> [u8; 32] {
(b"ethereum-chain", chain_id).using_encoded(blake2_256)
}
pub fn from_chain_id_with_key(chain_id: &u64, key: [u8; 20]) -> [u8; 32] {
(b"ethereum-chain", chain_id, key).using_encoded(blake2_256)
}

impl<AccountId> EthereumLocationsConverterFor<AccountId> {
pub fn from_chain_id(chain_id: &u64) -> [u8; 32] {
(b"ethereum-chain", chain_id).using_encoded(blake2_256)
}
pub fn from_chain_id_with_key(chain_id: &u64, key: [u8; 20]) -> [u8; 32] {
(b"ethereum-chain", chain_id, key).using_encoded(blake2_256)
}
}


pub type CallIndex = [u8; 2];
10 changes: 6 additions & 4 deletions bridges/snowbridge/primitives/router/src/inbound/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
//! Converts messages from Ethereum to XCM messages

use crate::inbound::{CallIndex, GlobalConsensusEthereumConvertsFor};
use crate::inbound::{CallIndex, EthereumLocationsConverterFor};
use codec::{Decode, Encode};
use core::marker::PhantomData;
use frame_support::{traits::tokens::Balance as BalanceT, PalletError};
Expand Down Expand Up @@ -247,7 +247,7 @@ MessageToXcm<

let bridge_location = Location::new(2, GlobalConsensus(network));

let owner = GlobalConsensusEthereumConvertsFor::<[u8; 32]>::from_chain_id(&chain_id);
let owner = EthereumLocationsConverterFor::<[u8; 32]>::from_chain_id(&chain_id);
let asset_id = Self::convert_token_address(network, token);
let create_call_index: [u8; 2] = CreateAssetCall::get();
let inbound_queue_pallet_index = InboundQueuePalletInstance::get();
Expand Down Expand Up @@ -409,6 +409,8 @@ MessageToXcm<
// Final destination is a 32-byte account on AssetHub
Destination::AccountId32 { id } =>
Ok(Location::new(0, [AccountId32 { network: None, id }])),
// Forwarding to a destination parachain is not allowed for PNA and is validated on the
// Ethereum side. https://github.com/Snowfork/snowbridge/blob/e87ddb2215b513455c844463a25323bb9c01ff36/contracts/src/Assets.sol#L216-L224
_ => Err(ConvertMessageError::InvalidDestination),
}?;

Expand Down Expand Up @@ -471,7 +473,7 @@ mod tests {
let contract_location = Location::new(2, [GlobalConsensus(NETWORK)]);

let account =
GlobalConsensusEthereumConvertsFor::<[u8; 32]>::convert_location(&contract_location)
EthereumLocationsConverterFor::<[u8; 32]>::convert_location(&contract_location)
.unwrap();

assert_eq!(account, expected_account);
Expand All @@ -482,7 +484,7 @@ mod tests {
let contract_location = Location::new(2, [GlobalConsensus(Polkadot), Parachain(1000)]);

assert_eq!(
GlobalConsensusEthereumConvertsFor::<[u8; 32]>::convert_location(&contract_location),
EthereumLocationsConverterFor::<[u8; 32]>::convert_location(&contract_location),
None,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ use frame_support::pallet_prelude::TypeInfo;
use hex_literal::hex;
use rococo_westend_system_emulated_network::asset_hub_westend_emulated_chain::genesis::AssetHubWestendAssetOwner;
use snowbridge_core::{outbound::OperatingMode, AssetMetadata, TokenIdOf};
use snowbridge_router_primitives::inbound::{
Command, Destination, EthereumLocationsConverterFor, MessageV1, VersionedMessage,
use snowbridge_router_primitives::inbound::EthereumLocationsConverterFor;
use snowbridge_router_primitives::inbound::v1::{
Command, Destination, MessageV1, VersionedMessage,
};
use sp_core::H256;
use testnet_parachains_constants::westend::snowbridge::EthereumNetwork;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
use parachains_common::{AccountId, Balance};
use snowbridge_beacon_primitives::{Fork, ForkVersions};
use snowbridge_core::{gwei, meth, AllowSiblingsOnly, PricingParameters, Rewards};
use snowbridge_router_primitives::{inbound::MessageToXcm, outbound::EthereumBlobExporter};
use snowbridge_router_primitives::{inbound::v1::MessageToXcm, outbound::EthereumBlobExporter};
use sp_core::H160;
use testnet_parachains_constants::rococo::{
currency::*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ snowbridge-system-runtime-api = { workspace = true }
snowbridge-core = { workspace = true }
snowbridge-pallet-ethereum-client = { workspace = true }
snowbridge-pallet-inbound-queue = { workspace = true }
snowbridge-pallet-inbound-queue-v2 = { workspace = true }
snowbridge-pallet-outbound-queue = { workspace = true }
snowbridge-outbound-queue-runtime-api = { workspace = true }
snowbridge-router-primitives = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ use crate::{
use parachains_common::{AccountId, Balance};
use snowbridge_beacon_primitives::{Fork, ForkVersions};
use snowbridge_core::{gwei, meth, AllowSiblingsOnly, PricingParameters, Rewards};
use snowbridge_router_primitives::{
outbound::{v1::EthereumBlobExporter, v2::EthereumBlobExporter as EthereumBlobExporterV2},
};
use snowbridge_router_primitives::outbound::EthereumBlobExporter;
use sp_core::H160;
use testnet_parachains_constants::westend::{
currency::*,
Expand All @@ -41,7 +39,7 @@ use benchmark_helpers::DoNothingRouter;
use frame_support::{parameter_types, weights::ConstantMultiplier};
use pallet_xcm::EnsureXcm;
use sp_runtime::{
traits::{ConstU32, ConstU8, Keccak256},
traits::{ConstU32, ConstU8, ConstU128, Keccak256},
FixedU128,
};
use xcm::prelude::{GlobalConsensus, InteriorLocation, Location, Parachain};
Expand Down Expand Up @@ -116,6 +114,9 @@ impl snowbridge_pallet_inbound_queue_v2::Config for Runtime {
type Helper = Runtime;
type WeightInfo = crate::weights::snowbridge_pallet_inbound_queue_v2::WeightInfo<Runtime>;
type AssetHubParaId = ConstU32<1000>;
type Token = Balances;
type XcmPrologueFee = ConstU128<1_000_000_000>;
type AssetTransactor = <xcm_config::XcmConfig as xcm_executor::Config>::AssetTransactor;
type MessageConverter = snowbridge_router_primitives::inbound::v2::MessageToXcm<EthereumNetwork, ConstU8<INBOUND_QUEUE_PALLET_INDEX>, EthereumSystem>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub mod xcm;

pub mod snowbridge_pallet_ethereum_client;
pub mod snowbridge_pallet_inbound_queue;
pub mod snowbridge_pallet_inbound_queue_v2;
pub mod snowbridge_pallet_outbound_queue;
pub mod snowbridge_pallet_system;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Autogenerated weights for `snowbridge_pallet_inbound_queue`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-09-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `macbook pro 14 m2`, CPU: `m2-arm64`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bridge-hub-rococo-dev"), DB CACHE: 1024

// Executed Command:
// target/release/polkadot-parachain
// benchmark
// pallet
// --chain=bridge-hub-rococo-dev
// --pallet=snowbridge_inbound_queue
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --steps
// 50
// --repeat
// 20
// --output
// ./parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/snowbridge_inbound_queue.rs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::Weight};
use core::marker::PhantomData;

/// Weight functions for `snowbridge_pallet_inbound_queue_v2`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> snowbridge_pallet_inbound_queue_v2::WeightInfo for WeightInfo<T> {
/// Storage: EthereumInboundQueue PalletOperatingMode (r:1 w:0)
/// Proof: EthereumInboundQueue PalletOperatingMode (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen)
/// Storage: EthereumBeaconClient ExecutionHeaders (r:1 w:0)
/// Proof: EthereumBeaconClient ExecutionHeaders (max_values: None, max_size: Some(136), added: 2611, mode: MaxEncodedLen)
/// Storage: EthereumInboundQueue Nonce (r:1 w:1)
/// Proof: EthereumInboundQueue Nonce (max_values: None, max_size: Some(20), added: 2495, mode: MaxEncodedLen)
/// Storage: System Account (r:1 w:1)
/// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
fn submit() -> Weight {
// Proof Size summary in bytes:
// Measured: `800`
// Estimated: `7200`
// Minimum execution time: 200_000_000 picoseconds.
Weight::from_parts(200_000_000, 0)
.saturating_add(Weight::from_parts(0, 7200))
.saturating_add(T::DbWeight::get().reads(9))
.saturating_add(T::DbWeight::get().writes(6))
}
}

0 comments on commit ee0bc27

Please sign in to comment.