substrate icon indicating copy to clipboard operation
substrate copied to clipboard

Add CallbackHandle to pallet-assets

Open Dinonard opened this issue 2 years ago • 4 comments

This PR adds an option to register callbacks for pallet-assets which are invoked when a new asset is created or an existing one destroyed.

Fixes issue #12279.

It's a simple change but requires a small runtime code update. Benchmarks shouldn't be impacted in case default empty implementation is used.

Note: Will prepare UT & companion PRs if/once changes are confirmed to be ok.

TODO

  • [ ] unit test
  • [ ] Companion PRs

Dinonard avatar Sep 20 '22 08:09 Dinonard

User @Dinonard, please sign the CLA here.

cla-bot-2021[bot] avatar Sep 20 '22 08:09 cla-bot-2021[bot]

Any comment maybe? :slightly_smiling_face:

I'd like to jump on UTs and companion PRs if there are no objections (I know the change is minimal).

Dinonard avatar Sep 26 '22 13:09 Dinonard

@Dinonard Thanks for making this PR! I've thinking a bit about this and it raises two questions:

  1. Is this not a usecase that could be covered by subscribing to the generated events?
  2. How will these callbacks interact with extrinsic weights? For eg, what if the caller of the function does very expensive calculations or storage operations in the callback? Won't we be unable to generate a correct weight in that state? And won't that be a possible attack vector?

cc @joepetrowski @jsidorenko

tonyalaribe avatar Oct 07 '22 10:10 tonyalaribe

Hi @tonyalaribe!

  1. Is this not a usecase that could be covered by subscribing to the generated events?

Event subscription is for interacting with the client, it's not part of the state transition function, so I don't believe this is applicable here.

  1. How will these callbacks interact with extrinsic weights?

In case current pallet-assets users don't use this callback, they can just keep the weight as they are. In case they decide to introduce new custom logic, they have to rerun the benchmarks themselves and use the new generated weights instead.

Dinonard avatar Oct 09 '22 23:10 Dinonard

The CI pipeline was cancelled due to failure one of the required jobs. The job name - cargo-check-benches The job logs - https://gitlab.parity.io/parity/mirrors/substrate/-/jobs/1969865

paritytech-cicd-pr avatar Oct 20 '22 07:10 paritytech-cicd-pr

I put it into the audit queue.

ggwpez avatar Oct 27 '22 19:10 ggwpez

@ggwpez sorry if this is a silly question, but could you tell me if and what I can do next?

Should I prepare cumulus companion? I see that contributing guide references polkadot companions, doesn't mention cumulus though.

Dinonard avatar Nov 14 '22 15:11 Dinonard

@ggwpez sorry if this is a silly question, but could you tell me if and what I can do next?

Should I prepare cumulus companion? I see that contributing guide references polkadot companions, doesn't mention cumulus though.

Sorry did not see.
We are waiting for audit. I will give them another ping. Better not change any code anymore then.
Your Cumulus companion looks good! Exactly how its done :laughing:

PS: Please dont force push - otherwise its difficult to see the change. You can just use git merge origin/master after pulling master.

ggwpez avatar Dec 05 '22 19:12 ggwpez

Thank you!

PS: Please dont force push - otherwise its difficult to see the change. You can just use git merge origin/master after pulling master.

My bad, will avoid force push in the future. I saw it's explained in the contributing guidelines :see_no_evil:

You can setup some helpers in your mock.rs for this: ...

Good to know! I will avoid changing this since you asked not to change any code anymore because of the audit (not sure if it's relevant since this is just a mock file but better safe than sorry).

Dinonard avatar Dec 06 '22 08:12 Dinonard

bot merge

ggwpez avatar Dec 08 '22 07:12 ggwpez

Error: Github API says "Allow edits from maintainers" is not enabled for https://github.com/paritytech/cumulus/pull/1947. The bot would use that permission to push the lockfile update after merging this PR. Please check https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork.

Can this be merged? :slightly_smiling_face:

Dinonard avatar Dec 20 '22 16:12 Dinonard

bot merge

ggwpez avatar Dec 20 '22 18:12 ggwpez

Error: Github API says "Allow edits from maintainers" is not enabled for https://github.com/paritytech/cumulus/pull/1947. The bot would use that permission to push the lockfile update after merging this PR. Please check https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork.

Can this be merged? slightly_smiling_face

@Dinonard Well, i tried. You see the error message from the bot:

Error: Github API says "Allow edits from maintainers" is not enabled for https://github.com/paritytech/cumulus/pull/1947. The bot would use that permission to push the lockfile update after merging this PR. Please check https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork.

ggwpez avatar Dec 20 '22 18:12 ggwpez

@Dinonard Well, i tried. You see the error message from the bot:

Thanks! Not sure what to make of that error but in cumulus companion it says:

Rule "Runtime files" needs in total 2 DISTINCT approvals, but 1 were given.

Quite strange given that that there are two distinct approvals.

Dinonard avatar Dec 21 '22 09:12 Dinonard

Quite strange given that that there are two distinct approvals.

You need another approval from someone in the polkadot-review group.

joepetrowski avatar Dec 21 '22 09:12 joepetrowski

bot merge

ggwpez avatar Dec 21 '22 12:12 ggwpez

Error: Github API says "Allow edits from maintainers" is not enabled for https://github.com/paritytech/cumulus/pull/1947. The bot would use that permission to push the lockfile update after merging this PR. Please check https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork.

You still did not update the Cumulus PR to be edit-able by maintainers @Dinonard

ggwpez avatar Dec 21 '22 12:12 ggwpez

You still did not update the Cumulus PR to be edit-able by maintainers @Dinonard

Do you know how we can enable "allow edits by maintainers" from a fork that lives under an org account? This thread suggests that that is not possible. Worst case, we'll have to close this PR and open a new one from an individual account fork, or you manually merge this.

hoonsubin avatar Dec 21 '22 12:12 hoonsubin

…or you manually merge this.

Yea. Then we know this for the future.

ggwpez avatar Dec 21 '22 13:12 ggwpez

…or you manually merge this.

Yea. Then we know this for the future.

Thanks!

I initially checked with @hoonsubin since I thought it might be due to me not having admin privileges under AstarNetwork/cumulus.

Should I modify the companion PR by updating the .lock file to point to latest master?

Dinonard avatar Dec 21 '22 13:12 Dinonard

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/polkadot-release-analysis-v0-9-37/1736/1

Polkadot-Forum avatar Jan 20 '23 07:01 Polkadot-Forum