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

feat: Connectors v2 message PoC #1292

Merged
merged 35 commits into from May 4, 2023
Merged

Conversation

wischli
Copy link
Contributor

@wischli wischli commented Mar 28, 2023

Description

Applies ConnectorsV2 message format based on the spec

TODO

  • Discuss requirement of CurrencyId to be representable by u128
  • Fix unit tests
  • Add mapping from CurrencyId to u128 via the new GeneralCurrencyIndex trait
  • Verify encoding/decoding updates in Solidity

Changes and Descriptions

  • Updates connectors Message enum based on the spec
    • Updates existing messages
    • Adds new messages
  • Updates existing Centrifuge chain extrinsics
  • Adds conversion for CurrencyId enum to u128 via two GeneralCurrencyIndex impls
  • Does not add flow/extrinsics for new messages, will be done in a subsequent PR

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

@NunoAlexandre
Copy link
Contributor

  • Discuss requirement of CurrencyId to be representable by u128

I have been thinking about this. The spec sort of presumes that every currency we will be identifying as a u128 has an inner GeneralIndex value within its MultiLocation representation. But that's not always the case, neither can/should we rely on that.

I'd suggest that we have a storage mapping from CurrencyId -> u128 that we set for every CurrencyId we want to support for these transfers. This grants us some benefits:

  • we can support new currencies to be transferred through Connectors without a runtime upgrade
  • we don't have a setup where EVERY currency registered in the asset registry is automatically connector-transferrable
  • other dAPPs or our own can query this state to know how this mapping is taking place
  • The community can have a saying on what tokens they find favourable to be connector-transferrable or not

On the Solidity side we will also need a similar mapping but from uint128 -> address.

What do you think? cc @offerijns @mustermeiszer

@wischli wischli self-assigned this Mar 30, 2023
@wischli wischli added D5-breaks-api Pull request changes public api. Document changes publicly. crcl-cross-chain Circle cross-chain related. labels Mar 30, 2023
@wischli wischli marked this pull request as ready for review April 3, 2023 07:34
Copy link
Contributor

@NunoAlexandre NunoAlexandre left a comment

Choose a reason for hiding this comment

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

First round 🚀

Things will still change a bit until the messages v2 spec is finalised so hang in there 🙏

libs/types/src/tokens.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/message.rs Outdated Show resolved Hide resolved
pallets/connectors/src/message.rs Outdated Show resolved Hide resolved
pallets/connectors/src/message.rs Outdated Show resolved Hide resolved
@wischli wischli force-pushed the feat/connectors-v2-message-poc branch from 06ef965 to 7726985 Compare April 19, 2023 15:32
@wischli wischli added the I8-enhancement An additional feature. label Apr 20, 2023
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/message.rs Outdated Show resolved Hide resolved
@wischli wischli requested a review from NunoAlexandre May 2, 2023 09:08
@wischli wischli marked this pull request as ready for review May 2, 2023 09:08
Co-authored-by: Jeroen Offerijns <Offerijns@users.noreply.github.com>
pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
pallets/connectors/src/message.rs Outdated Show resolved Hide resolved
Comment on lines 1495 to 1499
parameter_types! {
#[derive(scale_info::TypeInfo)]
pub const GeneralCurrencyPrefix: [u8; 12] = GENERAL_CURRENCY_INDEX_PREFIX;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can define this parameter_types in runtime-common, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this is a constant, I feel like it's better suited in the current place, e.g the constants module of libs/primitives/lib.rs. WDYT @mustermeiszer?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreeing with William here. All constants should stay in the primitives or the respective const of libs

NunoAlexandre
NunoAlexandre previously approved these changes May 2, 2023
Copy link
Contributor

@NunoAlexandre NunoAlexandre left a comment

Choose a reason for hiding this comment

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

🚀

Copy link
Collaborator

@mustermeiszer mustermeiszer 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 already.

We should note that we can remove the hard coupling with pallet_xcm_transactor once the pallet-connectors-gateway takes care of routing messages.

Thinks we can remove then

  • hard coupling
  • fn handle
  • fn add_connector
  • fn set_domain_router

Few changes I think are necessary:

  • Move impl TypeId for DomainAddress into id module of crate types
  • Move trait Codec to traits
  • fn update_member
    The adding of members should always go through the pallet-permissions interface. As we also coded the member list bot to use this API. So the extrinsic must only check if the permissions is existing. If yes, then submit message. Furthermore, we must block if the domain is local -- i.e. Centrifuge
  • fn transfer_tranche_tokens & fn transfer
    for both of these messages to the local domain should be forbidden. I think it is debatable if the gateway logic @cdamian will implement will ever allow to send messages to our own domain. I would argue no, but this is debatable. SO we should either agree on blocking this on the gateway side or already on the connectors side. WDYT?

Missing:

  • fn allow_pool_currency
    This is needed. The restriction is currently not 100% clear. I would say we restrict calling this only from democracy/AdminOrigin for now. Maybe we find a way to make it clear in the asset-registry or in the pallet-foreign-investments whether another currency can be used for investing.

@@ -249,6 +249,9 @@ pub mod constants {
pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 15 * CENTI_CFG + (bytes as Balance) * 6 * CENTI_CFG
}

/// The prefix for tokens managed by Connectors.
pub const GENERAL_CURRENCY_INDEX_PREFIX: [u8; 12] = *b"CfgCnctCurId";
Copy link
Collaborator

Choose a reason for hiding this comment

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

In order to not have clashes with external currencies and their representation in our CurrencyId::ForeignAssets(u128) I would like to have this prefix be a trimmed hash of the given bytes. Given that the alphabet is at most 52 values and u8 has room for 255 this will increase the probability of not having colissions. But maybe I am too worried there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be overkill but I am always supporting safer approaches. Unfortunately we lose out on the const property due to using blake2_128 and splitting. WDYT? d774926

@@ -393,7 +416,7 @@ pub mod pallet {
/// Transfer tranche tokens to a given address
#[pallet::weight(< T as Config >::WeightInfo::transfer())]
#[pallet::call_index(6)]
pub fn transfer(
pub fn transfer_tranche_tokens(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Block local domain!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch! 05dd755

Comment on lines 474 to 479
pub fn transfer(
origin: OriginFor<T>,
asset_id: CurrencyIdOf<T>,
domain_address: DomainAddress,
amount: <T as pallet::Config>::Balance,
) -> DispatchResult {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Block local domain!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch! 05dd755

pallets/connectors/src/lib.rs Outdated Show resolved Hide resolved
// TODO: Replace weight after benchmarking
#[pallet::weight(< T as Config >::WeightInfo::add_connector())]
#[pallet::call_index(8)]
pub fn add_currency(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have an issue for tracking that. This would be really important!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean the FIXME

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not have an existing Github issue but this is part of the asset metadata update which is owned by @NunoAlexandre

Copy link
Contributor Author

@wischli wischli May 4, 2023

Choose a reason for hiding this comment

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

Improved message in 05dd755

Comment on lines 1495 to 1499
parameter_types! {
#[derive(scale_info::TypeInfo)]
pub const GeneralCurrencyPrefix: [u8; 12] = GENERAL_CURRENCY_INDEX_PREFIX;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreeing with William here. All constants should stay in the primitives or the respective const of libs

mustermeiszer
mustermeiszer previously approved these changes May 4, 2023
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Approval under the constraint that we do a follow-up PR. This is not production code so we can go with this temporary inconsistency in main.

@wischli wischli dismissed stale reviews from mustermeiszer and NunoAlexandre via 787cc53 May 4, 2023 08:59
@wischli wischli requested a review from mustermeiszer May 4, 2023 09:10
@wischli wischli requested a review from NunoAlexandre May 4, 2023 12:56
Copy link
Collaborator

@mustermeiszer mustermeiszer 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 adapting to my comments.

@wischli wischli merged commit bd4a96b into main May 4, 2023
11 checks passed
@wischli wischli deleted the feat/connectors-v2-message-poc branch May 4, 2023 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crcl-cross-chain Circle cross-chain related. D5-breaks-api Pull request changes public api. Document changes publicly. I6-refactoring Code needs refactoring. I8-enhancement An additional feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants