-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Migrate pallet-example-offchain-worker to TransactionExtension API #10716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Migrate pallet-example-offchain-worker to TransactionExtension API #10716
Conversation
This commit migrates `pallet-example-offchain-worker` from the deprecated `ValidateUnsigned` trait to the modern `TransactionExtension` API using the `#[pallet::authorize]` attribute. Changes: - Replaced `#[pallet::validate_unsigned]` implementation with `#[pallet::authorize]` attributes on unsigned transaction calls - Updated `submit_price_unsigned` to use authorization attribute - Updated `submit_price_unsigned_with_signed_payload` to use authorization with signature verification - Changed `ensure_none` to `ensure_authorized` in unsigned transaction handlers - Updated documentation to reflect the new validation approach - Added comprehensive documentation about unsigned transaction validation This change demonstrates the recommended pattern for validating unsigned transactions and serves as a reference for other pallets migrating away from `ValidateUnsigned`.
a9a6166 to
05a3080
Compare
- Remove non-existent ValidateUnsignedPriceSubmission struct reference - Update Trait reference to Config (FRAME v2 syntax) These structs don't exist in the migrated code and would cause broken documentation links.
gui1117
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't do create_bare it will not work, instead we should create a general transaction in the offchain worker.
I am surprise the test are successful. Also the test environment use no transaction extensions, so if we want to test that AuthorizeCall is effectively validating the transaction, we need to at least put AuthorizeCall in the transaction extensions.
- Simplify authorize closures using .map() for cleaner code - Replace create_bare() with create_authorized_transaction() - create_bare only works for inherents and deprecated ValidateUnsigned - General transactions need transaction extensions for validation - Update Config trait bound from CreateBare to CreateAuthorizedTransaction - Update terminology from 'unsigned transaction' to 'general transaction' - Improve comments explaining custom validation and AuthorizeCall extension - Add clarification about transaction de-duplication via provides tag
- Simplify authorize closures using .map() - Remove CreateBare trait bound and implementation (no longer needed) - Replace send_unsigned_transaction with manual transaction creation using accounts_from_keys() and create_authorized_transaction() - Add CreateAuthorizedTransaction implementation in tests - Update test assertions to check for general transactions - Use fully qualified paths for SignedPayload::sign() to resolve type inference
Hi @gui1117, I think all remarks have been addressed. Also added an hackish integrity test to validate that |
bkchr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small things otherwise looks good.
|
@bkchr can this be merged? This is related to Deprecate ValidateUnsigned trait and #[pallet::validate_unsigned] attribute. Will try to migrate other pallets in the upcoming weeks. |
Summary
Part of #2415
This PR is a focused extraction from the larger PR #10150, specifically migrating only
pallet-example-offchain-workerto use the modernTransactionExtensionAPI.Changes
This PR migrates
pallet-example-offchain-workerfrom the deprecatedValidateUnsignedtrait to theTransactionExtensionAPI using the#[pallet::authorize]attribute.