Skip to content

Conversation

@dianpopa
Copy link

@dianpopa dianpopa commented Apr 20, 2024

Fungibles methods now take AssetId by reference instead of value where the value is not needed.

pallet-assets methods now also take AssetId by reference instead of value where the value is not needed.

This avoids a lot of cloning across the codebase.

There are more objects and traits that could do the same, but this PR already blew up in size as I was changing the most relevant ones. This "small" change is actually pretty big..

fixes #3968

Polkadot address: 14rY421S6kMMSRo9GkbMrWiVjD2UnbhFp6Boy9pDeYnBy1hD

Copy link
Contributor

@liamaharon liamaharon left a comment

Choose a reason for hiding this comment

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

Thanks for helping with this!

Comment on lines +537 to +538
assert_eq!(Fungibles::name(&asset_id.clone().into()), Vec::from(expected_name),);
assert_eq!(Fungibles::symbol(&asset_id.clone().into()), Vec::from(expected_symbol),);
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible to remove the .clones in scenarios like this or?

Copy link
Author

Choose a reason for hiding this comment

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

All these tests helper functions provide asset_id as impl Into<Fungibles::AssetId> + Clone. I would need to change the API of these functions, then a lot of test callsites.
I was thinking it's not worth the effort and the noise since these are only tests.

fn total_issuance(asset: Self::AssetId) -> Self::Balance {
match Criterion::convert(asset) {
fn total_issuance(asset: &Self::AssetId) -> Self::Balance {
match Criterion::convert(asset.clone()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I wonder if Criterion::convert should also take a ref?

Copy link
Author

Choose a reason for hiding this comment

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

I initially tried, but got lost in the sea of errors. There are so many generic types and trait bounds used here, hard to follow.

I will give it another try.

Copy link
Author

Choose a reason for hiding this comment

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

Can't make it work.. got as far as dianpopa@090c74e, maybe someone can help or do it in another PR.

@gilescope
Copy link
Contributor

Context: This is good clean up. It's because AssetId used to be Copy but we needed it to not be (we wanted to use MultiLocation as an AssetId but certainly for xcm v2 MultiLocation wasn't Copy).

@muharem muharem self-requested a review April 22, 2024 11:41
@paritytech-review-bot paritytech-review-bot bot requested a review from a team April 22, 2024 11:42
@cla-bot-2021
Copy link

cla-bot-2021 bot commented Apr 25, 2024

User @dianpopa, please sign the CLA here.

@dianpopa dianpopa requested a review from athei as a code owner April 27, 2024 10:33
@dianpopa
Copy link
Author

PR has a lot of changes, but the vast majority is test code because of the changed inner functions APIs. The "main" API changes are small I think.

@dianpopa
Copy link
Author

dianpopa commented May 6, 2024

@liamaharon @gilescope is there anything else required here?

Copy link
Contributor

@liamaharon liamaharon left a comment

Choose a reason for hiding this comment

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

Looks good, maybe some redundant .clones still in there?

type ForeignAssets = <PenpalA as PenpalAPallet>::ForeignAssets;
<ForeignAssets as Inspect<_>>::balance(system_para_native_asset_location.clone(), &receiver)
<ForeignAssets as Inspect<_>>::balance(
&system_para_native_asset_location.clone(),
Copy link
Contributor

@liamaharon liamaharon May 6, 2024

Choose a reason for hiding this comment

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

Does this and all similar still need .clone()?

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable-int
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6157942

@dianpopa
Copy link
Author

@liamaharon is this fix for #3968 still wanted?
I already put in considerable time, I will only continue if actually needed..
If yes, can you help with reviewers?

@franciscoaguirre
Copy link
Contributor

I agree this is a good fix and a tedious one (the amount of compiler errors, number of files), we should push for it to get merged before more conflicts pile up. @liamaharon thoughts?

@bkchr
Copy link
Member

bkchr commented Dec 9, 2025

Looks like the pr is stale.

@bkchr bkchr closed this Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fungibles methods should not consume AssetId

7 participants