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

snowbridge: allow account conversion for Ethereum accounts #6221

Merged

Conversation

acatangiu
Copy link
Contributor

@acatangiu acatangiu commented Oct 24, 2024

Replace GlobalConsensusEthereumConvertsFor with EthereumLocationsConverterFor that allows Location to AccountId conversion for the Ethereum network root as before, but also for Ethereum contracts and accounts.

The new converter only matches explicit parents: 2 Ethereum locations, meaning it should be used only on/by parachains.

@acatangiu acatangiu added the T15-bridges This PR/Issue is related to bridges. label Oct 24, 2024
@acatangiu acatangiu self-assigned this Oct 24, 2024
@acatangiu acatangiu requested a review from a team October 24, 2024 15:25
@acatangiu acatangiu force-pushed the enhance-ethereum-account-derivation branch from c06253a to bebb62f Compare October 24, 2024 15:29
where
AccountId: From<[u8; 32]> + Clone,
{
fn convert_location(location: &Location) -> Option<AccountId> {
match location.unpack() {
(_, [GlobalConsensus(Ethereum { chain_id })]) =>
(2, [GlobalConsensus(Ethereum { chain_id })]) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why be explicit on the parents here instead? Wouldnt this limit its usage to being relative to parachains?

It would be parents 1 if relative to the relaychain. It would also be parents 1 if relative to another Ethereum chain. This wont break any existing use cases though so maybe its fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I forgot to mention this as well in the description (edited now).

I prefer tightening the match to explicit parents: 2 since this converter is meant to be used by parachains only. I can't think of a valid (long-term) use case for the Relay chain to need to derive Ethereum locations.

It would also be parents 1 if relative to another Ethereum chain.

You mean if you use this converter in an Ethereum SC? I don't think there is such a real case, but if there will ever be I suggest adding a new entry to the match there or even using a separate converter since they would be different in output anyway (32bytes vs 20bytes).

Copy link
Contributor

@yrong yrong Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be parents 1 if relative to the relaychain

@alistair-singh Are you refering to another convert to convert a token location of PNA to a stable ID.

Then It's nothing to do with the above change, the above is for ENA and should be fine to set parents to 2.

@acatangiu
Copy link
Contributor Author

(btw: I am using this new converter in XCMv5 tests to Transact on parachain from Ethereum/Bob)

@acatangiu acatangiu force-pushed the enhance-ethereum-account-derivation branch from bebb62f to 1123e78 Compare October 28, 2024 13:00
@@ -17,14 +17,28 @@ parameter_types! {
}

#[test]
fn test_contract_location_with_network_converts_successfully() {
fn test_ethereum_network_converts_successfully() {
let expected_account: [u8; 32] =
hex!("ce796ae65569a670d0c1cc1ac12515a3ce21b5fbf729d63d7b289baad070139d");
let contract_location = Location::new(2, [GlobalConsensus(NETWORK)]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let contract_location = Location::new(2, [GlobalConsensus(NETWORK)]);
let ethereum_location = Location::new(2, [GlobalConsensus(NETWORK)]);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:
I'd squash first three tests into a single table-driven one.
Just like I did here
struct TestCase {
description,
location,
want
}

prdoc/pr_6221.prdoc Outdated Show resolved Hide resolved
@acatangiu acatangiu added this pull request to the merge queue Nov 5, 2024
Merged via the queue into paritytech:master with commit 6969be3 Nov 5, 2024
194 of 197 checks passed
@acatangiu acatangiu deleted the enhance-ethereum-account-derivation branch November 5, 2024 10:38
ordian added a commit that referenced this pull request Nov 5, 2024
* master: (129 commits)
  pallet-revive: Use `RUSTUP_TOOLCHAIN` if set (#6365)
  [eth-rpc] proxy /health (#6360)
  [Release|CI/CD] adjust release pipelines (#6366)
  Bump the known_good_semver group across 1 directory with 3 updates (#6339)
  Run check semver in MQ (#6287)
  [Deprecation] deprecate treasury `spend_local` call and related items (#6169)
  refactor and harden check_core_index (#6217)
  litep2p: Update litep2p to v0.8.0 (#6353)
  [pallet-staking] Additional check for virtual stakers (#5985)
  migrate pallet-remarks to v2 bench syntax (#6291)
  Remove leftover references of Wococo (#6361)
  snowbridge: allow account conversion for Ethereum accounts (#6221)
  authority-discovery: Populate DHT records with public listen addresses (#6298)
  Bounty Pallet: add `approve_bounty_with_curator` call to `bounties` pallet (#5961)
  Silent annoying log (#6351)
  [pallet-revive] rework balance transfers (#6187)
  `statement-distribution`: RFC103 implementation (#5883)
  Disable flaky tests reported in #6343 / #6345 (#6346)
  migrate pallet-recovery to benchmark V2 syntax (#6299)
  inclusion emulator: correctly handle UMP signals (#6178)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T15-bridges This PR/Issue is related to bridges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants