Skip to content

Conversation

@RomarQ
Copy link
Contributor

@RomarQ RomarQ commented Dec 31, 2025

Summary

Part of #2415

This PR is a focused extraction from the larger PR #10150, specifically migrating only pallet-example-offchain-worker to use the modern TransactionExtension API.

Changes

This PR migrates pallet-example-offchain-worker from the deprecated ValidateUnsigned trait to the TransactionExtension API using the #[pallet::authorize] attribute.

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`.
@RomarQ RomarQ force-pushed the romarq/migrate-offchain-worker-to-tx-extension branch from a9a6166 to 05a3080 Compare December 31, 2025 14:37
@RomarQ RomarQ marked this pull request as ready for review December 31, 2025 14:37
@RomarQ RomarQ requested a review from a team as a code owner December 31, 2025 14:37
- 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.
Copy link
Contributor

@gui1117 gui1117 left a 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.

RomarQ added 3 commits January 1, 2026 09:22
- 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
@RomarQ RomarQ marked this pull request as draft January 1, 2026 13:34
@RomarQ RomarQ marked this pull request as ready for review January 2, 2026 09:11
@RomarQ
Copy link
Contributor Author

RomarQ commented Jan 2, 2026

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.

Hi @gui1117,

I think all remarks have been addressed. Also added an hackish integrity test to validate that AuthorizeCall is added as Transaction Extension in the runtime configuration. Will try to think of a better way to validating a possible misconfiguration in the runtime.

RomarQ added a commit to RomarQ/polkadot-sdk that referenced this pull request Jan 3, 2026
Copy link
Member

@bkchr bkchr left a 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.

@RomarQ
Copy link
Contributor Author

RomarQ commented Jan 14, 2026

@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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants