Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Frame: Give Referendum SubmitOrigin argument #14326

Merged
merged 6 commits into from
Jun 12, 2023

Conversation

gavofyork
Copy link
Member

When determining whether a submission origin should be allowed, it is useful to be able to inspect the track they are submitting for, since it may be desired to have less-privileged origins be valid for some tracks but not others.

This alters the type bound accordingly. To minimise breakage across the ecosystem, all type bounders in Substrate are updated to support the EnsureOriginWithArg trait as well as the EnsureOrigin trait. To facilitate this support both in Substrate and downstream repos, a macro allowing EnsureOrigin implementors to naively support EnsureOriginWithArg is introduced.

🚨 Code Changes

If you are using Referenda pallet and find a build error around the SubmitOrigin (which is probably a custom origin), then simply wrap the type with frame_support::AsEnsureOriginWithArg to get an EnsureOriginWithArg impl. E.g.

impl pallet_referenda::Config for Runtime {
    type SubmitOrigin = MyEnsureOriginImpl;
    // snip
}

Would become:

impl pallet_referenda::Config for Runtime {
    type SubmitOrigin = frame_support::AsEnsureOriginWithArg<MyEnsureOriginImpl>;
    // snip
}

@gavofyork gavofyork requested review from a team June 8, 2023 13:39
@gavofyork gavofyork added A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. B1-note_worthy Changes should be noted in the release notes T1-runtime This PR/Issue is related to the topic “runtime”. labels Jun 8, 2023
Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

Just 1 comment and 1 nit.

frame/support/src/traits/dispatch.rs Outdated Show resolved Hide resolved
frame/support/src/traits/dispatch.rs Outdated Show resolved Hide resolved
///
/// The argument is ignored, much like in [AsEnsureOriginWithArg].
#[macro_export]
macro_rules! ignoring_arg {
Copy link
Contributor

@sam0x17 sam0x17 Jun 9, 2023

Choose a reason for hiding this comment

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

I would rename to impl_ensure_origin_with_arg_for_ensure_origin (or some reasonable name) just so we're painfully explicit here

Copy link
Contributor

@sam0x17 sam0x17 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, would prefer that we make that macro name more clear

@gavofyork gavofyork merged commit b72c475 into master Jun 12, 2023
@gavofyork gavofyork deleted the gav-referendum-submit-origin-with-arg branch June 12, 2023 08:10
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
* Referedum's SubmitOrigin should have an arg

* Fixes

* Nits and two extra utils

* Fixes

* Fixes
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants