Conversation
#[pallet::authorize(...)] macro attribute and AuthorizeCall system transaction extension#[pallet::authorize(...)] macro attribute and AuthorizeCall system transaction extension
#[pallet::authorize(...)] macro attribute and AuthorizeCall system transaction extension#[pallet::authorize(...)] macro attribute and AuthorizeCall system transaction extension
This was referenced Nov 1, 2024
Merged
github-merge-queue bot
pushed a commit
that referenced
this pull request
Nov 13, 2024
…tionExtension::validate` (#6323) ## Meta This PR is part of 4 PR: * #6323 * #6324 * #6325 * #6326 ## Description One goal of transaction extension is to get rid or unsigned transactions. But unsigned transaction validation has access to the `TransactionSource`. The source is used for unsigned transactions that the node trust and don't want to pay upfront. Instead of using transaction source we could do: the transaction is valid if it is signed by the block author, conceptually it should work, but it doesn't look so easy. This PR add `TransactionSource` to the validate function for transaction extensions
github-merge-queue bot
pushed a commit
that referenced
this pull request
Nov 13, 2024
…tionExtension::validate` (#6323) ## Meta This PR is part of 4 PR: * #6323 * #6324 * #6325 * #6326 ## Description One goal of transaction extension is to get rid or unsigned transactions. But unsigned transaction validation has access to the `TransactionSource`. The source is used for unsigned transactions that the node trust and don't want to pay upfront. Instead of using transaction source we could do: the transaction is valid if it is signed by the block author, conceptually it should work, but it doesn't look so easy. This PR add `TransactionSource` to the validate function for transaction extensions
gui1117
added a commit
that referenced
this pull request
Nov 14, 2024
…tionExtension::validate` (#6323) ## Meta This PR is part of 4 PR: * #6323 * #6324 * #6325 * #6326 ## Description One goal of transaction extension is to get rid or unsigned transactions. But unsigned transaction validation has access to the `TransactionSource`. The source is used for unsigned transactions that the node trust and don't want to pay upfront. Instead of using transaction source we could do: the transaction is valid if it is signed by the block author, conceptually it should work, but it doesn't look so easy. This PR add `TransactionSource` to the validate function for transaction extensions (cherry picked from commit 8e3d929)
gui1117
added a commit
that referenced
this pull request
Nov 15, 2024
…tionExtension::validate` (#6323) ## Meta This PR is part of 4 PR: * #6323 * #6324 * #6325 * #6326 ## Description One goal of transaction extension is to get rid or unsigned transactions. But unsigned transaction validation has access to the `TransactionSource`. The source is used for unsigned transactions that the node trust and don't want to pay upfront. Instead of using transaction source we could do: the transaction is valid if it is signed by the block author, conceptually it should work, but it doesn't look so easy. This PR add `TransactionSource` to the validate function for transaction extensions (cherry picked from commit 8e3d929)
Contributor
georgepisaltu
left a comment
There was a problem hiding this comment.
Looks great, just some comments and questions
| fn authorize( | ||
| &self, | ||
| source: TransactionSource, | ||
| ) -> Option<Result<(ValidTransaction, Weight), TransactionValidityError>>; |
Contributor
There was a problem hiding this comment.
Worth mentioning that generally when we have an Option<Result<(... we should have a dedicated type for the return, but I think this will never be manually implemented and having it like this makes it easier to work with in the macros. Users get to see TransactionValidityWithRefund as the authorize closure return type, so in terms of UX it's good.
Contributor
|
Command "update-ui" has started 🚀 See logs here |
Contributor
|
Command "update-ui" has finished ✅ See logs here |
This was referenced Mar 6, 2025
castillax
pushed a commit
that referenced
this pull request
May 12, 2025
…ribute and `AuthorizeCall` system transaction extension (#6324) ## Meta This PR is part of 4 PR: * #6323 * #6324 * #6325 * #6326 ## Description * new attribute `#[pallet::authorize(..)]`, this attributes takes a function which returns the validity of the call. * new attribute `#[pallet::weight_of_authorize(..)]`, same as `#[pallet::weight(..)]` defines the pre dispatch weight of the `authorize` function. It can also be retrieved from `WeightInfo` under the name: `authorize_$call_name`. * new trait `Authorize` in frame-support: implemented on the call for pallets and runtime, and used by `AuthorizeCall` transaction extension in frame-system. * new origin variant in frame origin: `Origin::Authorized`: a bit similar to `Unsigned` but used for general transactions. * new transaction extension: `AuthorizeCall` in frame system. This is meant to be used first in the transaction extension pipeline. It will call the authorize function and change the origin to authorized * new method: `ensure_authorized`. ## Usage ```rust # #[allow(unused)] #[frame_support::pallet] pub mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; #[pallet::pallet] pub struct Pallet<T>(_); #[pallet::config] pub trait Config: frame_system::Config {} #[pallet::call] impl<T: Config> Pallet<T> { #[pallet::weight(Weight::zero())] #[pallet::authorize(|_source, foo| if *foo == 42 { let refund = Weight::zero(); let validity = ValidTransaction::default(); Ok((validity, refund)) } else { Err(TransactionValidityError::Invalid(InvalidTransaction::Call)) })] #[pallet::weight_of_authorize(Weight::zero())] #[pallet::call_index(0)] pub fn some_call(origin: OriginFor<T>, arg: u32) -> DispatchResult { ensure_authorized(origin)?; Ok(()) } #[pallet::weight(Weight::zero())] // We can also give the callback as a function #[pallet::authorize(Pallet::<T>::authorize_some_other_call)] #[pallet::weight_of_authorize(Weight::zero())] #[pallet::call_index(1)] pub fn some_other_call(origin: OriginFor<T>, arg: u32) -> DispatchResult { ensure_authorized(origin)?; Ok(()) } } impl<T: Config> Pallet<T> { fn authorize_some_other_call( source: TransactionSource, foo: &u32 ) -> TransactionValidityWithRefund { if *foo == 42 { let refund = Weight::zero(); let validity = ValidTransaction::default(); Ok((validity, refund)) } else { Err(TransactionValidityError::Invalid(InvalidTransaction::Call)) } } } #[frame_benchmarking::v2::benchmarks] mod benchmarks { use super::*; use frame_benchmarking::v2::BenchmarkError; #[benchmark] fn authorize_some_call() -> Result<(), BenchmarkError> { let call = Call::<T>::some_call { arg: 42 }; #[block] { use frame_support::pallet_prelude::Authorize; call.authorize(TransactionSource::External) .ok_or("Call must give some authorization")??; } Ok(()) } } } ``` --------- Co-authored-by: GitHub Action <action@github.com> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
alvicsam
pushed a commit
that referenced
this pull request
Oct 17, 2025
…ribute and `AuthorizeCall` system transaction extension (#6324) ## Meta This PR is part of 4 PR: * #6323 * #6324 * #6325 * #6326 ## Description * new attribute `#[pallet::authorize(..)]`, this attributes takes a function which returns the validity of the call. * new attribute `#[pallet::weight_of_authorize(..)]`, same as `#[pallet::weight(..)]` defines the pre dispatch weight of the `authorize` function. It can also be retrieved from `WeightInfo` under the name: `authorize_$call_name`. * new trait `Authorize` in frame-support: implemented on the call for pallets and runtime, and used by `AuthorizeCall` transaction extension in frame-system. * new origin variant in frame origin: `Origin::Authorized`: a bit similar to `Unsigned` but used for general transactions. * new transaction extension: `AuthorizeCall` in frame system. This is meant to be used first in the transaction extension pipeline. It will call the authorize function and change the origin to authorized * new method: `ensure_authorized`. ## Usage ```rust # #[allow(unused)] #[frame_support::pallet] pub mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; #[pallet::pallet] pub struct Pallet<T>(_); #[pallet::config] pub trait Config: frame_system::Config {} #[pallet::call] impl<T: Config> Pallet<T> { #[pallet::weight(Weight::zero())] #[pallet::authorize(|_source, foo| if *foo == 42 { let refund = Weight::zero(); let validity = ValidTransaction::default(); Ok((validity, refund)) } else { Err(TransactionValidityError::Invalid(InvalidTransaction::Call)) })] #[pallet::weight_of_authorize(Weight::zero())] #[pallet::call_index(0)] pub fn some_call(origin: OriginFor<T>, arg: u32) -> DispatchResult { ensure_authorized(origin)?; Ok(()) } #[pallet::weight(Weight::zero())] // We can also give the callback as a function #[pallet::authorize(Pallet::<T>::authorize_some_other_call)] #[pallet::weight_of_authorize(Weight::zero())] #[pallet::call_index(1)] pub fn some_other_call(origin: OriginFor<T>, arg: u32) -> DispatchResult { ensure_authorized(origin)?; Ok(()) } } impl<T: Config> Pallet<T> { fn authorize_some_other_call( source: TransactionSource, foo: &u32 ) -> TransactionValidityWithRefund { if *foo == 42 { let refund = Weight::zero(); let validity = ValidTransaction::default(); Ok((validity, refund)) } else { Err(TransactionValidityError::Invalid(InvalidTransaction::Call)) } } } #[frame_benchmarking::v2::benchmarks] mod benchmarks { use super::*; use frame_benchmarking::v2::BenchmarkError; #[benchmark] fn authorize_some_call() -> Result<(), BenchmarkError> { let call = Call::<T>::some_call { arg: 42 }; #[block] { use frame_support::pallet_prelude::Authorize; call.authorize(TransactionSource::External) .ok_or("Call must give some authorization")??; } Ok(()) } } } ``` --------- Co-authored-by: GitHub Action <action@github.com> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
6 tasks
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Meta
This PR is part of 4 PR:
TransactionSourceas argument inTransactionExtension::validate#6323#[pallet::authorize(...)]macro attribute andAuthorizeCallsystem transaction extension #6324#[pallet::authorize(...)]to migrate unsigned in system: tasks + apply_authorized_call #6325#[pallet::authorize(...)]to migrate all unsigned in polkadot-sdk #6326Description
#[pallet::authorize(..)], this attributes takes a function which returns the validity of the call.#[pallet::weight_of_authorize(..)], same as#[pallet::weight(..)]defines the pre dispatch weight of theauthorizefunction. It can also be retrieved fromWeightInfounder the name:authorize_$call_name.Authorizein frame-support: implemented on the call for pallets and runtime, and used byAuthorizeCalltransaction extension in frame-system.Origin::Authorized: a bit similar toUnsignedbut used for general transactions.AuthorizeCallin frame system. This is meant to be used first in the transaction extension pipeline. It will call the authorize function and change the origin to authorizedensure_authorized.Usage