Skip to content

Pallet assets: new status LiveAndNoPrivilege and new call revoke_all_privilege#4150

Open
gui1117 wants to merge 66 commits intoparitytech:masterfrom
gui1117:gui-assets-revoke-through-status
Open

Pallet assets: new status LiveAndNoPrivilege and new call revoke_all_privilege#4150
gui1117 wants to merge 66 commits intoparitytech:masterfrom
gui1117:gui-assets-revoke-through-status

Conversation

@gui1117
Copy link
Copy Markdown
Contributor

@gui1117 gui1117 commented Apr 16, 2024

Some coins don't want to have any privilege role once the distribution is done. We have seen that with $PINK coins which transfered its ownership to a killed proxy account, ensuring nobody can have this privilege.
The issue is that this is not easily discoverable. For instance light client can't get this proof easily.

So this PR introduces:

  • new asset status: live and no privilege. Under this status all Owner, Issuer, Freezer, Admin privilege are null.

  • new call: revoke_all_privilege. Can be called by owner or ForceOrigin, asset must be live. It set the status LiveAndNoPrivilege, and it also freezes the metadata.

  • new config associated type: DepositDestinationOnRevocation. When owner revoke its privilege, the deposit goes to this handler. Note that if ForceOrigin calls revoke_all_privilege then owner get its deposit back.

@gui1117 gui1117 requested a review from a team as a code owner April 16, 2024 08:23
.saturating_add(T::DbWeight::get().writes(1_u64))
}
fn revoke_all_privileges() -> Weight {
Weight::zero()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Weight::zero()
Weight::MAX

Safer default

Copy link
Copy Markdown
Contributor Author

@gui1117 gui1117 Apr 23, 2024

Choose a reason for hiding this comment

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

yes, I now ran benchmarks on my machine for a better default.

It should be fixed


/// Check that owner is same as in asset details and that asset status is not
/// `LiveAndNoPrivileges`.
pub(super) fn check_owner_right(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or verify_owner. Same for others.

Suggested change
pub(super) fn check_owner_right(
pub(super) fn check_owner(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed, I changed internal API for a safer implementation, tell me what you think

@gui1117 gui1117 changed the title Pallet assets: new status LiveAndNoPrivilege and new call revoke_all_privilege WIP: Pallet assets: new status LiveAndNoPrivilege and new call revoke_all_privilege Apr 23, 2024
@joepetrowski joepetrowski added the T2-pallets This PR/Issue is related to a particular pallet. label Apr 23, 2024
@paritytech-review-bot paritytech-review-bot bot requested a review from a team April 23, 2024 10:01
Asset::<T, I>::insert(&id, d);

Self::deposit_event(Event::TeamChanged { asset_id: id.clone(), issuer, admin, freezer });
Self::deposit_event(Event::OwnerChanged { asset_id: id, owner });
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added events here. This is unrelated to the PR, Let me know if this is unwanted

@gui1117 gui1117 requested review from a team and athei as code owners April 23, 2024 10:43
@gui1117 gui1117 changed the title WIP: Pallet assets: new status LiveAndNoPrivilege and new call revoke_all_privilege Pallet assets: new status LiveAndNoPrivilege and new call revoke_all_privilege Apr 23, 2024
@joepetrowski joepetrowski requested a review from muharem August 7, 2024 07:15
@gui1117 gui1117 force-pushed the gui-assets-revoke-through-status branch from a4baa63 to 905f658 Compare August 7, 2024 09:21
@paritytech-cicd-pr
Copy link
Copy Markdown

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/7138716

[package]
name = "pallet-assets"
version = "29.1.0"
version = "30.0.0"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this will be done when released to avoid multiple version increments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, fixed in 6594d94

let d = maybe_details.as_mut().ok_or(Error::<T, I>::Unknown)?;
ensure!(d.status == AssetStatus::Live, Error::<T, I>::AssetNotLive);
ensure!(origin == d.freezer, Error::<T, I>::NoPermission);
Self::ensure_live_asset(&d)?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

may be something like d.is_live(), etc .., so we could have it more consistent. it is easy to make a mistake with the statuses

Copy link
Copy Markdown
Contributor Author

@gui1117 gui1117 Sep 6, 2024

Choose a reason for hiding this comment

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

I added the method on asset details: is_live. 6594d94


/// Reset the team for the asset with the given `id`.
///
/// If the asset status is `LiveAndNoPrivileges` then it is changed to `Live`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe worth mentioning something in ResetTeam trait doc that it is a force reset

Copy link
Copy Markdown
Contributor Author

@gui1117 gui1117 Sep 6, 2024

Choose a reason for hiding this comment

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

Would you prefer to change the trait to have 2 functions: try_reset_team and force_reset_team instead?

EDIT: keeping the trait with just an additional doc could be fine considering any trait using ResetTeam would know that the owner doesn't exist when the status is LiveAndNoPrivileges

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I only improved the doc: d0a8ab2

I think it is fine to keep the trait as it is, because reset_team is quite authoritative by itself, and caller should know why it can or cannot reset the team.

}
match d.try_set_team(&owner, &issuer, &admin, &freezer) {
Ok(()) => (),
Err(SetTeamError::AssetStatusLiveAndNoPrivileges) => log::error!(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we still update the status on this failure? we probably wanna exit with this arm from the function

Copy link
Copy Markdown
Contributor Author

@gui1117 gui1117 Sep 6, 2024

Choose a reason for hiding this comment

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

Yes ok, I added a new error variant: InternalError and abort in case of such internal error. 6594d94


match details.try_set_owner(&owner) {
Ok(()) => (),
Err(SetTeamError::AssetStatusLiveAndNoPrivileges) => log::error!(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should not we exit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes ok 6594d94

);
match res {
Ok(()) => (),
Err(SetTeamError::AssetStatusLiveAndNoPrivileges) => log::error!(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

status will change to Live even though we failed to change the team

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes ok 6594d94

Err(origin) => Some(ensure_signed(origin)?),
};
let id: T::AssetId = id.into();
let mut asset = Asset::<T, I>::get(id.clone()).ok_or(Error::<T, I>::Unknown)?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should work with a reference, no cloned needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great catch, fixed in 6594d94

Metadata::<T, I>::insert(&id, &new_metadata);

asset.deposit = Zero::zero();
asset.status = AssetStatus::LiveAndNoPrivileges;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AFAIK we do not have invalid account address for our crypto. not sure how reasonable (probably not) would be to have some valid but random address to be used as a common null address.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is indeed a bit safer in case of error in the runtime.

We can copy the logic of pure proxy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thinking again, the best would be a special account owned by the asset pallet (same as the treasury account), which doesn't have any action.

I will do it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done in 5d30a4e

I copied the pallet proxy logic.

@eskimor
Copy link
Copy Markdown
Member

eskimor commented Mar 31, 2025

@gui1117 thanks for this initiative! Being able to drop privileges easily (and discoverable) is super important! Any chance we can get this over the finish line?

@gui1117
Copy link
Copy Markdown
Contributor Author

gui1117 commented Apr 8, 2025

@gui1117 thanks for this initiative! Being able to drop privileges easily (and discoverable) is super important! Any chance we can get this over the finish line?

No idea, I think the PR is ready for review, I don't want to merge master if nobody reviews it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T2-pallets This PR/Issue is related to a particular pallet.

Projects

Status: Audited

Development

Successfully merging this pull request may close these issues.