Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions polkadot/runtime/common/src/claims/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ use frame_support::{
};
use frame_system::RawOrigin;
use secp_utils::*;
use sp_runtime::{
traits::{DispatchTransaction, ValidateUnsigned},
DispatchResult,
};
use sp_runtime::{traits::DispatchTransaction, DispatchResult};

const SEED: u32 = 0;

Expand Down Expand Up @@ -74,6 +71,9 @@ fn create_claim_attest<T: Config>(input: u32) -> DispatchResult {
mod benchmarks {
use super::*;

#[allow(deprecated)]
use sp_runtime::traits::ValidateUnsigned;

// Benchmark `claim` including `validate_unsigned` logic.
#[benchmark]
fn claim() -> Result<(), BenchmarkError> {
Expand Down Expand Up @@ -104,6 +104,7 @@ mod benchmarks {
{
let call = <Call<T> as Decode>::decode(&mut &*call_enc)
.expect("call is encoded above, encoding must be correct");
#[allow(deprecated)]
super::Pallet::<T>::validate_unsigned(source, &call)
.map_err(|e| -> &'static str { e.into() })?;
call.dispatch_bypass_filter(RawOrigin::None.into())?;
Expand Down Expand Up @@ -168,6 +169,7 @@ mod benchmarks {
{
let call = <Call<T> as Decode>::decode(&mut &*call_enc)
.expect("call is encoded above, encoding must be correct");
#[allow(deprecated)]
super::Pallet::<T>::validate_unsigned(source, &call)
.map_err(|e| -> &'static str { e.into() })?;
call.dispatch_bypass_filter(RawOrigin::None.into())?;
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/claims/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ pub mod pallet {
}
}

#[allow(deprecated)]
#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/common/src/claims/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ fn real_eth_sig_works() {
}

#[test]
#[allow(deprecated)]
fn validate_unsigned_works() {
use sp_runtime::traits::ValidateUnsigned;
let source = sp_runtime::transaction_validity::TransactionSource::External;
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/parachains/src/disputes/slashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ pub mod pallet {
}
}

#[allow(deprecated)]
#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/parachains/src/paras/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ pub mod pallet {
}
}

#[allow(deprecated)]
#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
Expand Down
2 changes: 2 additions & 0 deletions polkadot/runtime/parachains/src/paras/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,7 @@ fn pvf_check_submit_vote() {

let call =
Call::include_pvf_check_statement { stmt: stmt.clone(), signature: signature.clone() };
#[allow(deprecated)]
let validate_unsigned =
<Paras as ValidateUnsigned>::validate_unsigned(TransactionSource::InBlock, &call)
.map(|_| ());
Expand Down Expand Up @@ -2263,6 +2264,7 @@ fn apply_authorized_force_set_current_code_works() {
code: ValidationCode|
-> (Result<_, _>, DispatchResultWithPostInfo) {
let call = Call::apply_authorized_force_set_current_code { para, new_code: code.clone() };
#[allow(deprecated)]
let validate_unsigned =
<Paras as ValidateUnsigned>::validate_unsigned(TransactionSource::InBlock, &call)
.map(|_| ());
Expand Down
38 changes: 38 additions & 0 deletions prdoc/pr_10150.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
title: Deprecate `ValidateUnsigned` trait and `#[pallet::validate_unsigned]` attribute.

doc:
- audience: [Runtime Dev, Runtime User]
description: |
Deprecate the `ValidateUnsigned` trait and `#[pallet::validate_unsigned]` attribute as part of phase 2 of Extrinsic Horizon.

crates:
- name: sp-runtime
bump: minor
- name: frame-system
bump: patch
- name: frame-support
bump: patch
- name: frame-support-procedural
bump: minor
- name: polkadot-runtime-common
bump: patch
- name: polkadot-runtime-parachains
bump: patch
- name: pallet-babe
bump: patch
- name: pallet-beefy
bump: patch
- name: pallet-election-provider-multi-phase
bump: patch
- name: pallet-election-provider-multi-block
bump: patch
- name: frame-executive
bump: patch
- name: pallet-grandpa
bump: patch
- name: pallet-im-online
bump: patch
- name: pallet-mixnet
bump: patch
- name: substrate-test-runtime
bump: patch
1 change: 1 addition & 0 deletions substrate/frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ pub mod pallet {
}
}

#[allow(deprecated)]
#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ fn report_equivocation_invalid_equivocation_proof() {
}

#[test]
#[allow(deprecated)]
fn report_equivocation_validate_unsigned_prevents_duplicates() {
use sp_runtime::transaction_validity::{
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/beefy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ pub mod pallet {
}
}

#[allow(deprecated)]
#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/beefy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ fn report_double_voting_invalid_equivocation_proof() {
}

#[test]
#[allow(deprecated)]
fn report_double_voting_validate_unsigned_prevents_duplicates() {
use sp_runtime::transaction_validity::{
InvalidTransaction, TransactionPriority, TransactionSource, TransactionValidity,
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/election-provider-multi-block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2308,9 +2308,7 @@ mod election_provider {
Phase,
};
use frame_election_provider_support::{BoundedSupport, BoundedSupports, ElectionProvider};
use frame_support::{
assert_storage_noop, testing_prelude::bounded_vec, unsigned::ValidateUnsigned,
};
use frame_support::{assert_storage_noop, testing_prelude::bounded_vec};

// This is probably the most important test of all, a basic, correct scenario. This test should
// be studied in detail, and all of the branches of how it can go wrong or diverge from the
Expand Down Expand Up @@ -2626,7 +2624,9 @@ mod election_provider {
}

#[test]
#[allow(deprecated)]
fn call_to_elect_should_prevent_any_submission() {
use frame_support::unsigned::ValidateUnsigned;
ExtBuilder::full().build_and_execute(|| {
roll_to_signed_open();
assert!(MultiBlock::current_phase().is_signed());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ mod benchmarks {

#[block]
{
assert_ok!(Pallet::<T>::validate_unsigned(TransactionSource::Local, &call));
#[allow(deprecated)]
let result = Pallet::<T>::validate_unsigned(TransactionSource::Local, &call);
assert_ok!(result);
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ mod pallet {
}
}

#[allow(deprecated)]
#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
Expand Down Expand Up @@ -370,6 +371,7 @@ mod pallet {
}

#[cfg(test)]
#[allow(deprecated)]
mod validate_unsigned {
use frame_election_provider_support::Support;
use frame_support::{
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,7 @@ pub mod pallet {
PreDispatchDifferentRound,
}

#[allow(deprecated)]
#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T> {
type Call = Call<T>;
Expand Down
10 changes: 9 additions & 1 deletion substrate/frame/election-provider-multi-phase/src/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,13 +1109,17 @@ mod tests {
use sp_runtime::{
bounded_vec,
offchain::storage_lock::{BlockAndTime, StorageLock},
traits::{Dispatchable, ValidateUnsigned, Zero},
traits::{Dispatchable, Zero},
ModuleError, PerU16,
};

#[allow(deprecated)]
use sp_runtime::traits::ValidateUnsigned;

type Assignment = crate::unsigned::Assignment<Runtime>;

#[test]
#[allow(deprecated)]
fn validate_unsigned_retracts_wrong_phase() {
ExtBuilder::default().desired_targets(0).build_and_execute(|| {
let solution = RawSolution::<TestNposSolution> {
Expand Down Expand Up @@ -1188,6 +1192,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn validate_unsigned_retracts_low_score() {
ExtBuilder::default().desired_targets(0).build_and_execute(|| {
roll_to_unsigned();
Expand Down Expand Up @@ -1234,6 +1239,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn validate_unsigned_retracts_incorrect_winner_count() {
ExtBuilder::default().desired_targets(1).build_and_execute(|| {
roll_to_unsigned();
Expand All @@ -1260,6 +1266,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn priority_is_set() {
ExtBuilder::default()
.miner_tx_priority(20)
Expand Down Expand Up @@ -1905,6 +1912,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn ocw_solution_must_have_correct_round() {
let (mut ext, pool) = ExtBuilder::default().build_offchainify(0);
ext.execute_with(|| {
Expand Down
22 changes: 19 additions & 3 deletions substrate/frame/examples/offchain-worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ documentation.

- [`pallet_example_offchain_worker::Trait`](./trait.Trait.html)
- [`Call`](./enum.Call.html)
- [`Module`](./struct.Module.html)
- [`Pallet`](./struct.Pallet.html)
- [`ValidateUnsignedPriceSubmission`](./struct.ValidateUnsignedPriceSubmission.html)

**This pallet serves as an example showcasing Substrate off-chain worker and is not meant to be
used in production.**
Expand All @@ -23,7 +24,22 @@ and prepare either signed or unsigned transaction to feed the result back on cha
The on-chain logic will simply aggregate the results and store last `64` values to compute
the average price.
Additional logic in OCW is put in place to prevent spamming the network with both signed
and unsigned transactions, and custom `UnsignedValidator` makes sure that there is only
one unsigned transaction floating in the network.
and unsigned transactions. The pallet uses the `#[pallet::authorize]` attribute to validate
unsigned transactions, ensuring that only one unsigned transaction can be accepted per
`UnsignedInterval` blocks.

## Unsigned Transaction Validation

This pallet demonstrates how to validate unsigned transactions using the modern
`#[pallet::authorize]` attribute instead of the deprecated `ValidateUnsigned` trait.

The `#[pallet::authorize]` attribute is used on the unsigned transaction calls:
- `submit_price_unsigned` - Validates a simple unsigned transaction
- `submit_price_unsigned_with_signed_payload` - Validates an unsigned transaction with a signed payload

The authorization logic checks:
1. Block number is within the expected window (via `NextUnsignedAt` storage)
2. The price data is valid
3. For signed payloads, verifies the signature using the authority's public key

License: MIT-0
Loading
Loading