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
Conversation
I have been thinking about this. The spec sort of presumes that every currency we will be identifying as a I'd suggest that we have a storage mapping from
On the Solidity side we will also need a similar mapping but from What do you think? cc @offerijns @mustermeiszer |
There was a problem hiding this 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 🙏
06ef965
to
7726985
Compare
Co-authored-by: Jeroen Offerijns <Offerijns@users.noreply.github.com>
runtime/development/src/lib.rs
Outdated
parameter_types! { | ||
#[derive(scale_info::TypeInfo)] | ||
pub const GeneralCurrencyPrefix: [u8; 12] = GENERAL_CURRENCY_INDEX_PREFIX; | ||
} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
There was a problem hiding this 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
intoid
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. Centrifugefn 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.
libs/primitives/src/lib.rs
Outdated
@@ -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"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block local domain!
There was a problem hiding this comment.
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
pub fn transfer( | ||
origin: OriginFor<T>, | ||
asset_id: CurrencyIdOf<T>, | ||
domain_address: DomainAddress, | ||
amount: <T as pallet::Config>::Balance, | ||
) -> DispatchResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block local domain!
There was a problem hiding this comment.
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
// TODO: Replace weight after benchmarking | ||
#[pallet::weight(< T as Config >::WeightInfo::add_connector())] | ||
#[pallet::call_index(8)] | ||
pub fn add_currency( |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the FIXME
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improved message in 05dd755
runtime/development/src/lib.rs
Outdated
parameter_types! { | ||
#[derive(scale_info::TypeInfo)] | ||
pub const GeneralCurrencyPrefix: [u8; 12] = GENERAL_CURRENCY_INDEX_PREFIX; | ||
} | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this 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.
There was a problem hiding this 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.
Description
Applies ConnectorsV2 message format based on the spec
TODO
CurrencyId
to be representable byu128
CurrencyId
tou128
via the newGeneralCurrencyIndex
traitChanges and Descriptions
Message
enum based on the specCurrencyId
enum tou128
via twoGeneralCurrencyIndex
implsCurrencyId
Pallet
Checklist: