Skip to content

review & cleanup#401

Closed
xlc wants to merge 5 commits intoChainSafe:mainfrom
xlc:review-and-cleanup
Closed

review & cleanup#401
xlc wants to merge 5 commits intoChainSafe:mainfrom
xlc:review-and-cleanup

Conversation

@xlc
Copy link
Contributor

@xlc xlc commented Sep 20, 2021

Some minor cleanup & fixes.
Add some inline comment for questions.

Some more clone can be removed by having help method taking &T::AccountId instead of T::AccountId.
I don't see any mechanism to prevent admin from minting of other non-related assets. Some refactor is likely required to prevent it by leveraging some type system.
XCM related fee handling also needs more consideration. The fee will be paid by parachain account so the pallets needs to charge someone for the fee.. Also with new introduction of BuyWeights, the current code needs update.

@CLAassistant
Copy link

CLAassistant commented Sep 20, 2021

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

Thanks so much for this review!

Some more clone can be removed by having help method taking &T::AccountId instead of T::AccountId.

Definitely, will follow up on this #403

I don't see any mechanism to prevent admin from minting of other non-related assets. Some refactor is likely required to prevent it by leveraging some type system.

Yes, the initial minting process design (add_asset) left some room for improvement. We received some similar feedback and are about to make registering and minting to separate parts #383 so that add_asset will require that the asset is already registered.

XCM related fee handling also needs more consideration. The fee will be paid by parachain account so the pallets needs to charge someone for the fee..

Very good point, we still need to do our research on the substrate native xcm benchmarking suite. Since these XCM Transact calls will be executed via governance we expect them to be paid from the treasury directly.
There will likely be a fee charged by deposit in order to cover potential XCM staking-related calls. This will definitely benefit from the xcm weightinfo.
also we expect all the Transact calls to be improved significantly with the upcoming Query/Response Message types, but I guess they're scheduled for v2.

Also with new introduction of BuyWeights, the current code needs update.

We're about to tackle this with the migration to xcm::latest

I'd like to include your improvements, so if you're fine with it, I'll strip your comments and merge the PR.


// mint the given units of the SAFT asset into the treasury's account
T::Currency::deposit(asset_id, &Self::treasury_account(), units)?;
T::Currency::deposit(asset_id, &Self::treasury_account(), units)?; // ??? Bryan - what prevents this from minting other assets? e.g. DOT
Copy link
Contributor

Choose a reason for hiding this comment

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

the AssetIndex::add_saft function will be called by SaftRegistry::add_saft pallet which is executed via governance. The asset_id will therefore be part of the proposal.

The check

Assets::<T>::try_mutate(asset_id, |maybe_available| -> DispatchResult {
		if let Some(exits) = maybe_available.replace(AssetAvailability::Saft) {
			ensure!(exits.is_saft(), Error::<T>::ExpectedSAFT);
		}
		Ok(())
})?;

ensures that the id is either nonexistent or a known non liquid SAFT id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the question is, via which governance? If this is installed to Karura / Acala runtime, it is not acceptable to allow anyone other than root to have permission to mint arbitrary tokens

Copy link
Contributor

@mattsse mattsse Sep 21, 2021

Choose a reason for hiding this comment

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

I see. The thing with SAFT is, that there are no tokens (yet). docs.polkadotindex.com/safts-within-the-pint-index
So we would need some further restrictions on this, or disable the SAFT registry pallet for the Acala integration entirely.
The latter would make more sense since AssetId here would be CurrencyId which is a fixed set with reserved tokens right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One approach is do some sub currency id that is fully owned by PINT pallets. Then PINT pallets can have full privilege to this.
So we need: type AssetId: From<PintAssetId> + TryInto<PintAssetId> and

enum PintAssetId {
  PINT,
  SAFT(u32), // or whatever identifier
}

and for Acala

enum CurrencyId {
 // current variants,
  Pint(PintAssetId),
}

Copy link
Contributor

Choose a reason for hiding this comment

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

That's an elegant solution, we'll go with that.

Self::ensure_not_native_asset(&asset_id)?;
// mint asset into the treasury account
T::Currency::deposit(asset_id, &Self::treasury_account(), units)?;
T::Currency::deposit(asset_id, &Self::treasury_account(), units)?; // ??? Bryan - where is this token coming from?
Copy link
Contributor

Choose a reason for hiding this comment

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

After some feedback, we're already in the process of splitting the registering and minting (add_asset) part. #383 #387
So at this point, we expect the asset was registered before (register_asset).

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 still don't fully understand. You cannot mint any assets other than PINT token. So there shouldn't be any deposit call.

Copy link
Contributor

@mattsse mattsse Sep 21, 2021

Choose a reason for hiding this comment

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

Initially, this was intended as governance-approved mint process for PINT and assets alike.
You're right this doesn't seem to be sound, since there is no guarantee that these assets we're depositing here are also available in the PINT's parachain account on the asset's native chain, right?
You'd recommend that we require that these assets were also send via xcm? so that the deposit here becomes a transfer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I am happy with a transfer from account controlled by pallet or the caller of a tx.

Comment on lines 500 to 501
// ??? Bryan - who is paying for the XCM execution fee on dest chain?

Copy link
Contributor

Choose a reason for hiding this comment

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

since this is executed via governance proposal we expect this to be paid from the PINT treasury account.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but there needs to be some code to burn KSM from PINT treasury to accomplish the fee paid on relaychain.

Copy link
Contributor

Choose a reason for hiding this comment

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

good point, this is still a missing feature that needs to be implemented.

@xlc
Copy link
Contributor Author

xlc commented Sep 20, 2021

I'd like to include your improvements, so if you're fine with it, I'll strip your comments and merge the PR.

Please go ahead.

@clearloop
Copy link
Contributor

Fixed CI on the PR of forked repo, it should be triggered on the next commit : )

@xlc xlc force-pushed the review-and-cleanup branch from fec944a to 4ab2904 Compare September 20, 2021 22:17
Copy link
Contributor

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

amazing, thank you so much!
will take care of failing tests due to refactor to DispatchResult

Copy link
Contributor

@clearloop clearloop left a comment

Choose a reason for hiding this comment

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

Thanks! @xlc

@mattsse what about packing the discussion in this pr into a new issue, there is a fixing for the tests run after this pr in #407

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.

4 participants