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

Fix sibling location #1077

Merged
merged 9 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 0 additions & 4 deletions contracts/src/Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ contract Gateway is IGateway, IInitializable {
bytes4 internal immutable BRIDGE_HUB_PARA_ID_ENCODED;
bytes32 internal immutable BRIDGE_HUB_AGENT_ID;

// AssetHub
ParaID internal immutable ASSET_HUB_PARA_ID;
bytes32 internal immutable ASSET_HUB_AGENT_ID;

// ChannelIDs
ChannelID internal constant PRIMARY_GOVERNANCE_CHANNEL_ID = ChannelID.wrap(bytes32(uint256(1)));
ChannelID internal constant SECONDARY_GOVERNANCE_CHANNEL_ID = ChannelID.wrap(bytes32(uint256(2)));
Expand Down
6 changes: 2 additions & 4 deletions parachain/pallets/system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ use xcm_executor::traits::ConvertLocation;

use snowbridge_core::{
gwei, meth, outbound::ConstantGasMeter, sibling_sovereign_account, AgentId, AllowSiblingsOnly,
DescribeHere, ParaId, PricingParameters, Rewards,
ParaId, PricingParameters, Rewards,
};
use sp_runtime::{
traits::{AccountIdConversion, BlakeTwo256, IdentityLookup, Keccak256},
AccountId32, BuildStorage, FixedU128,
};
use xcm::prelude::*;
use xcm_builder::{DescribeAllTerminal, DescribeFamily, HashedDescription};

#[cfg(feature = "runtime-benchmarks")]
use crate::BenchmarkHelper;
Expand Down Expand Up @@ -221,8 +220,7 @@ impl crate::Config for Test {
type RuntimeEvent = RuntimeEvent;
type OutboundQueue = OutboundQueue;
type SiblingOrigin = pallet_xcm_origin::EnsureXcm<AllowSiblingsOnly>;
type AgentIdOf =
HashedDescription<AgentId, (DescribeHere, DescribeFamily<DescribeAllTerminal>)>;
type AgentIdOf = snowbridge_core::AgentIdOf;
type TreasuryAccount = TreasuryAccount;
type Token = Balances;
type DefaultPricingParameters = Parameters;
Expand Down
6 changes: 5 additions & 1 deletion parachain/primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use xcm::prelude::{
Junctions::{Here, X1},
MultiLocation,
};
use xcm_builder::DescribeLocation;
use xcm_builder::{DescribeAllTerminal, DescribeFamily, DescribeLocation, HashedDescription};

/// The ID of an agent contract
pub type AgentId = H256;
Expand Down Expand Up @@ -168,3 +168,7 @@ impl DescribeLocation for DescribeHere {
}
}
}

/// Creates an AgentId from a MultiLocation. An AgentId is a unique mapping to a Agent contract on
/// Ethereum which acts as the sovereign account for the MultiLocation.
pub type AgentIdOf = HashedDescription<H256, (DescribeHere, DescribeFamily<DescribeAllTerminal>)>;
7 changes: 3 additions & 4 deletions parachain/primitives/router/src/outbound/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ where
SendError::Unroutable
})?;

// local_sub is relative to the relaychain. No conversion needed.
let local_sub_location: MultiLocation = local_sub.into();
let agent_id = match AgentHashedDescription::convert_location(&local_sub_location) {
let source_location: MultiLocation = MultiLocation { parents: 1, interior: local_sub };
let agent_id = match AgentHashedDescription::convert_location(&source_location) {
Some(id) => id,
None => {
log::error!(target: "xcm::ethereum_blob_exporter", "unroutable due to not being able to create agent id. '{local_sub_location:?}'");
log::error!(target: "xcm::ethereum_blob_exporter", "unroutable due to not being able to create agent id. '{source_location:?}'");
return Err(SendError::Unroutable)
},
};
Expand Down
36 changes: 31 additions & 5 deletions parachain/primitives/router/src/outbound/tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use frame_support::parameter_types;
use hex_literal::hex;
use snowbridge_core::outbound::{Fee, SendError, SendMessageFeeProvider};

use snowbridge_core::{
outbound::{Fee, SendError, SendMessageFeeProvider},
AgentIdOf,
};
use xcm::v3::prelude::SendError as XcmSendError;
use xcm_builder::{DescribeAllTerminal, DescribeFamily, HashedDescription};

pub type AgentIdOf = HashedDescription<H256, DescribeFamily<DescribeAllTerminal>>;

use super::*;

Expand Down Expand Up @@ -1035,3 +1034,30 @@ fn xcm_converter_convert_with_non_ethereum_chain_beneficiary_yields_beneficiary_
let result = converter.convert();
assert_eq!(result.err(), Some(XcmConverterError::BeneficiaryResolutionFailed));
}

#[test]
fn test_describe_asset_hub() {
let legacy_location: MultiLocation =
MultiLocation { parents: 0, interior: X1(Parachain(1000)) };
let legacy_agent_id = AgentIdOf::convert_location(&legacy_location).unwrap();
assert_eq!(
legacy_agent_id,
hex!("72456f48efed08af20e5b317abf8648ac66e86bb90a411d9b0b713f7364b75b4").into()
);
let location: MultiLocation = MultiLocation { parents: 1, interior: X1(Parachain(1000)) };
let agent_id = AgentIdOf::convert_location(&location).unwrap();
assert_eq!(
agent_id,
hex!("81c5ab2571199e3188135178f3c2c8e2d268be1313d029b30f534fa579b69b79").into()
)
}

#[test]
fn test_describe_here() {
let location: MultiLocation = MultiLocation { parents: 0, interior: Here };
let agent_id = AgentIdOf::convert_location(&location).unwrap();
assert_eq!(
agent_id,
hex!("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314").into()
)
}
2 changes: 1 addition & 1 deletion smoketest/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub const BRIDGE_HUB_AGENT_ID: [u8; 32] =
hex!("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314");
// Agent for asset hub parachain 1000
pub const ASSET_HUB_AGENT_ID: [u8; 32] =
hex!("72456f48efed08af20e5b317abf8648ac66e86bb90a411d9b0b713f7364b75b4");
hex!("81c5ab2571199e3188135178f3c2c8e2d268be1313d029b30f534fa579b69b79");
claravanstaden marked this conversation as resolved.
Show resolved Hide resolved
// Agent for penpal parachain 2000
pub const SIBLING_AGENT_ID: [u8; 32] =
hex!("5097ee1101e90c3aadb882858c59a22108668021ec81bce9f4930155e5c21e59");
Expand Down
2 changes: 1 addition & 1 deletion web/packages/test/scripts/set-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export BRIDGE_HUB_AGENT_ID="${BRIDGE_HUB_AGENT_ID:-0x03170a2e7597b7b7e3d84c05391
assethub_ws_url="${ASSET_HUB_WS_URL:-ws://127.0.0.1:12144}"
assethub_seed="${ASSET_HUB_SEED:-//Alice}"
export ASSET_HUB_PARAID="${ASSET_HUB_PARAID:-1000}"
export ASSET_HUB_AGENT_ID="${ASSET_HUB_AGENT_ID:-0x72456f48efed08af20e5b317abf8648ac66e86bb90a411d9b0b713f7364b75b4}"
export ASSET_HUB_AGENT_ID="${ASSET_HUB_AGENT_ID:-0x81c5ab2571199e3188135178f3c2c8e2d268be1313d029b30f534fa579b69b79}"

export ASSET_HUB_CHANNEL_ID="0xc173fac324158e77fb5840738a1a541f633cbec8884c6a601c567d2b376a0539"
export PENPAL_CHANNEL_ID="0xa69fbbae90bb6096d59b1930bbcfc8a3ef23959d226b1861deb7ad8fb06c6fa3"
Expand Down
Loading