Skip to content

Commit

Permalink
Deprecate scheduler traits v1 and v2 (#3718)
Browse files Browse the repository at this point in the history
This PR add `#[deprecated]` attribute to v1 and v2 of the schedule
trait. Proposed in this issue:
#3676

```rust
#[allow(deprecated)]
#[deprecated = "traits::schedule::v1 is deprecated. Please use v3 instead."]
pub mod v1 {
...
}

#[allow(deprecated)]
#[deprecated = "traits::schedule::v2 is deprecated. Please use v3 instead."]
pub mod v2 {
...
}
```

polkadot address: 19nSqFQorfF2HxD3oBzWM3oCh4SaCRKWt1yvmgaPYGCo71J

---------

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
  • Loading branch information
3 people authored Mar 28, 2024
1 parent 5d314eb commit daf04f0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
13 changes: 13 additions & 0 deletions prdoc/pr_3718.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Deprecate scheduler traits v1 and v2

doc:
- audience: Runtime Dev
description: |
Add `#[deprecated]` attribute to scheduler traits v1 and v2 to deprecate old versions

crates:
- name: frame-support
- name: pallet-scheduler
3 changes: 3 additions & 0 deletions substrate/frame/scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@ impl<T: Config> Pallet<T> {
}
}

#[allow(deprecated)]
impl<T: Config> schedule::v2::Anon<BlockNumberFor<T>, <T as Config>::RuntimeCall, T::PalletsOrigin>
for Pallet<T>
{
Expand Down Expand Up @@ -1480,6 +1481,8 @@ impl<T: Config> schedule::v2::Anon<BlockNumberFor<T>, <T as Config>::RuntimeCall
}
}

// TODO: migrate `schedule::v2::Anon` to `v3`
#[allow(deprecated)]
impl<T: Config> schedule::v2::Named<BlockNumberFor<T>, <T as Config>::RuntimeCall, T::PalletsOrigin>
for Pallet<T>
{
Expand Down
18 changes: 16 additions & 2 deletions substrate/frame/support/src/traits/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<T: Decode, H> MaybeHashed<T, H> {
}
}

// TODO: deprecate
#[deprecated(note = "Use `v3` instead. Will be removed after September 2024.")]
pub mod v1 {
use super::*;

Expand Down Expand Up @@ -218,10 +218,12 @@ pub mod v1 {
fn next_dispatch_time(id: Vec<u8>) -> Result<BlockNumber, ()>;
}

#[allow(deprecated)]
impl<T, BlockNumber, Call, RuntimeOrigin> Anon<BlockNumber, Call, RuntimeOrigin> for T
where
T: v2::Anon<BlockNumber, Call, RuntimeOrigin>,
{
#[allow(deprecated)]
type Address = T::Address;

fn schedule(
Expand All @@ -232,29 +234,36 @@ pub mod v1 {
call: Call,
) -> Result<Self::Address, DispatchError> {
let c = MaybeHashed::<Call, T::Hash>::Value(call);

#[allow(deprecated)]
T::schedule(when, maybe_periodic, priority, origin, c)
}

fn cancel(address: Self::Address) -> Result<(), ()> {
#[allow(deprecated)]
T::cancel(address)
}

fn reschedule(
address: Self::Address,
when: DispatchTime<BlockNumber>,
) -> Result<Self::Address, DispatchError> {
#[allow(deprecated)]
T::reschedule(address, when)
}

fn next_dispatch_time(address: Self::Address) -> Result<BlockNumber, ()> {
#[allow(deprecated)]
T::next_dispatch_time(address)
}
}

#[allow(deprecated)]
impl<T, BlockNumber, Call, RuntimeOrigin> Named<BlockNumber, Call, RuntimeOrigin> for T
where
T: v2::Named<BlockNumber, Call, RuntimeOrigin>,
{
#[allow(deprecated)]
type Address = T::Address;

fn schedule_named(
Expand All @@ -266,27 +275,31 @@ pub mod v1 {
call: Call,
) -> Result<Self::Address, ()> {
let c = MaybeHashed::<Call, T::Hash>::Value(call);
#[allow(deprecated)]
T::schedule_named(id, when, maybe_periodic, priority, origin, c)
}

fn cancel_named(id: Vec<u8>) -> Result<(), ()> {
#[allow(deprecated)]
T::cancel_named(id)
}

fn reschedule_named(
id: Vec<u8>,
when: DispatchTime<BlockNumber>,
) -> Result<Self::Address, DispatchError> {
#[allow(deprecated)]
T::reschedule_named(id, when)
}

fn next_dispatch_time(id: Vec<u8>) -> Result<BlockNumber, ()> {
#[allow(deprecated)]
T::next_dispatch_time(id)
}
}
}

// TODO: deprecate
#[deprecated(note = "Use `v3` instead. Will be removed after September 2024.")]
pub mod v2 {
use super::*;

Expand Down Expand Up @@ -478,4 +491,5 @@ pub mod v3 {
}
}

#[allow(deprecated)]
pub use v1::*;

0 comments on commit daf04f0

Please sign in to comment.