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

refactor: Use VersionedLocation in RestrictedTransferLocation #1861

Conversation

wischli
Copy link
Contributor

@wischli wischli commented Jun 5, 2024

Description

  • Replaces inner v4::Location of RestrictedTransferLocation::XCM with VersionedLocation
  • Updates allowlist benchmarks from v1 to v2

Why so many benchmark and test changes?

This change broke transfer allowlist benchmarks which required T::AccountId <-> T::Location conversion. Unfortunately, it was not possible to implement From/TryFrom for AccountId and RestrictedTransferLocation because of the the blanket Rust From<T> for T implementation which conflicts with any custom implementation involving the same type for both From and TryFrom.

AFAICT, I could have either added a custom conversion trait or gone with my current proposal. Unfortunately, my proposal required refactoring unit tests which used u64 as AccountId and a custom enum for T::Location which conflicted with my new benchmark restriction of Config<AccountId = AccountId, Location = RestrictedTransferLocation.

Due to some weird error logs, I also converted the benchmarks from v1 to v2.

Checklist:

  • I have added Rust doc comments to structs, enums, traits and functions
  • I have made corresponding changes to the documentation
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works

@wischli wischli added D2-notify Pull request can be merged and notification about changes should be documented. I6-refactoring Code needs refactoring. labels Jun 5, 2024
@wischli wischli self-assigned this Jun 5, 2024
@@ -29,105 +32,282 @@ use super::*;

const BENCHMARK_CURRENCY_ID: FilterCurrency = FilterCurrency::Specific(CurrencyId::ForeignAsset(1));

benchmarks! {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: Apart from updating to v2 and adjusting the where clause a bit as well as providing the default_location wrapper, I did not change anything here apart from removing redundant clones.

…n' into wf/polkadot-v1.7.2-restricted-transfer-location
chain="development-local"
chain="development"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Feature creep: Remainder from removing the redundant development-local in #1844.

@wischli wischli requested a review from lemunozm June 5, 2024 16:00
Copy link
Contributor

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for this changes! Just some questions

libs/types/src/locations.rs Show resolved Hide resolved
Comment on lines -282 to -284
let destination: Location = (*dest.clone())
.try_into()
.map_err(|()| Error::<T>::BadVersion)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool! It seems like the it wanted to be so 👍🏻

Deserialize,
Serialize,
)]
pub enum Location {
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I liked this in order to not import centrifuge runtime types in pallets. Did you find some issues with the current Location used here?


add_transfer_allowance_no_existing_metadata {
#[benchmark]
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for organizing this!

Comment on lines 34 to 39

impl From<AccountId32> for RestrictedTransferLocation {
fn from(value: AccountId32) -> Self {
Self::Local(value)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you have an error with this? I remember runtime benchmarks not working without this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me check again with this enabled. I don't know why but recently I am often fooled by my cargo cache which I can only fix by cleaning completely.

This change broke transfer allowlist benchmarks which required T::AccountId <-> T::Location conversion. Unfortunately, it was not possible to implement From/TryFrom for AccountId and RestrictedTransferLocation because of the the blanket Rust From<T> for T implementation which conflicts with any custom implementation involving the same type for both From and TryFrom.

AFAICT, I could have either added a custom conversion trait or gone with my current proposal. Unfortunately, my proposal required refactoring unit tests which used u64 as AccountId and a custom enum for T::Location which conflicted with my new benchmark restriction of Config<AccountId = AccountId, Location = RestrictedTransferLocation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, it was not possible to implement From/TryFrom for AccountId and RestrictedTransferLocation

The above compiled in main IIRC 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently, it works for AccountId32 as part of our current codebase. However, it does not work for AccountId even though that's the same type under the hood 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted in a7cf00f

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that is something I previously battled with. I do not understand why TBH. Even I was not able to find the impl T for T implementation running cargo doc. There is something weird in the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am happy to hear even you don't understand it. It really frustrated me yesterday..

@wischli wischli requested a review from lemunozm June 6, 2024 09:43
Copy link
Contributor

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

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

Everything is perfect! Thanks for consider my suggestions! 🚀

@lemunozm
Copy link
Contributor

lemunozm commented Jun 6, 2024

Click the button when you want!

@wischli wischli merged commit 3d97a95 into polkadot-v1.7.2-transfer-location Jun 6, 2024
@wischli wischli deleted the wf/polkadot-v1.7.2-restricted-transfer-location branch June 6, 2024 10:42
@wischli wischli added this to the Centrifuge 1029 milestone Jun 6, 2024
lemunozm added a commit that referenced this pull request Jun 6, 2024
* migration for restricted transfer location

* add correct location for centrifuge

* minor changes

* fix benchmarks

* fix IT compilation

* chore: extend v1.7.2 transfer location migration (#1858)

* feat: add pre + post-upgrade

* feat: add nuking migration for dev and demo

* fix: remove account list for demo

* refactor: Use `VersionedLocation` in `RestrictedTransferLocation` (#1861)

* feat: add pre + post-upgrade

* feat: add nuking migration for dev and demo

* fix: remove account list for demo

* refactor: use VersionedLocation

* fix: transfer allowlist benchmarks + tests

* fix: clippy

* fix: benchmark cli

* fix: revert tight coupling

* fmt

* fix IT compilation

---------

Co-authored-by: William Freudenberger <w.freude@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D2-notify Pull request can be merged and notification about changes should be documented. I6-refactoring Code needs refactoring.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants