Skip to content
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

Cleanup deprecated apis #1764

Closed
wants to merge 8 commits into from
Closed
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
3 changes: 2 additions & 1 deletion cumulus/parachains/pallets/collective-content/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
//! Tests.

use super::{mock::*, *};
use frame_support::{assert_noop, assert_ok, error::BadOrigin, pallet_prelude::Pays};
use frame_support::{assert_noop, assert_ok, pallet_prelude::Pays};
use sp_runtime::traits::BadOrigin;

/// returns CID hash of 68 bytes of given `i`.
fn create_cid(i: u8) -> OpaqueCid {
Expand Down
6 changes: 2 additions & 4 deletions polkadot/runtime/common/src/paras_registrar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,7 @@ mod tests {
mock::conclude_pvf_checking, paras_registrar, traits::Registrar as RegistrarTrait,
};
use frame_support::{
assert_noop, assert_ok,
error::BadOrigin,
parameter_types,
assert_noop, assert_ok, parameter_types,
traits::{ConstU32, OnFinalize, OnInitialize},
};
use frame_system::limits;
Expand All @@ -712,7 +710,7 @@ mod tests {
use sp_io::TestExternalities;
use sp_keyring::Sr25519Keyring;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
traits::{BadOrigin, BlakeTwo256, IdentityLookup},
transaction_validity::TransactionPriority,
BuildStorage, Perbill,
};
Expand Down
3 changes: 2 additions & 1 deletion polkadot/runtime/parachains/src/assigner_on_demand/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ use crate::{
paras::{ParaGenesisArgs, ParaKind},
scheduler::common::Assignment,
};
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
use frame_support::{assert_noop, assert_ok};
use pallet_balances::Error as BalancesError;
use primitives::{BlockNumber, SessionIndex, ValidationCode};
use sp_runtime::traits::BadOrigin;
use sp_std::collections::btree_map::BTreeMap;

fn schedule_blank_para(id: ParaId, parakind: ParaKind) {
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/alliance/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

//! Tests for the alliance pallet.

use frame_support::{assert_noop, assert_ok, error::BadOrigin};
use frame_support::{assert_noop, assert_ok};
use frame_system::{EventRecord, Phase};
use sp_runtime::traits::BadOrigin;

use super::*;
use crate::mock::*;
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ use environmental::*;
use frame_support::{
dispatch::{GetDispatchInfo, Pays, PostDispatchInfo, RawOrigin, WithPostDispatchInfo},
ensure,
error::BadOrigin,
traits::{
fungible::{Inspect, Mutate, MutateHold},
ConstU32, Contains, Get, Randomness, Time,
Expand All @@ -136,7 +135,7 @@ use pallet_contracts_primitives::{
use scale_info::TypeInfo;
use smallvec::Array;
use sp_runtime::{
traits::{Convert, Dispatchable, Hash, Saturating, StaticLookup, Zero},
traits::{BadOrigin, Convert, Dispatchable, Hash, Saturating, StaticLookup, Zero},
DispatchError, RuntimeDebug,
};
use sp_std::{fmt::Debug, prelude::*};
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
use codec::{Decode, Encode};
use frame_support::{
ensure,
error::BadOrigin,
traits::{
defensive_prelude::*,
schedule::{v3::Named as ScheduleNamed, DispatchTime},
Expand All @@ -166,7 +165,7 @@ use frame_support::{
};
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
use sp_runtime::{
traits::{Bounded as ArithBounded, One, Saturating, StaticLookup, Zero},
traits::{BadOrigin, Bounded as ArithBounded, One, Saturating, StaticLookup, Zero},
ArithmeticError, DispatchError, DispatchResult,
};
use sp_std::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2519,7 +2519,7 @@ pub mod pallet {
) -> DispatchResult {
let mut bonded_pool = match ensure_root(origin.clone()) {
Ok(()) => BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?,
Err(frame_support::error::BadOrigin) => {
Err(sp_runtime::traits::BadOrigin) => {
let who = ensure_signed(origin)?;
let bonded_pool =
BondedPool::<T>::get(pool_id).ok_or(Error::<T>::PoolNotFound)?;
Expand Down
6 changes: 2 additions & 4 deletions substrate/frame/ranked-collective/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
use std::collections::BTreeMap;

use frame_support::{
assert_noop, assert_ok,
error::BadOrigin,
parameter_types,
assert_noop, assert_ok, parameter_types,
traits::{ConstU16, ConstU32, ConstU64, EitherOf, Everything, MapSuccess, Polling},
};
use sp_core::{Get, H256};
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup, ReduceBy},
traits::{BadOrigin, BlakeTwo256, IdentityLookup, ReduceBy},
BuildStorage,
};

Expand Down
6 changes: 0 additions & 6 deletions substrate/frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2264,12 +2264,6 @@ pub mod pallet_macros {
pub use frame_support_procedural::genesis_build;
}

#[deprecated(note = "Will be removed after July 2023; Use `sp_runtime::traits` directly instead.")]
pub mod error {
#[doc(hidden)]
pub use sp_runtime::traits::{BadOrigin, LookupError};
}

#[doc(inline)]
pub use frame_support_procedural::register_default_impl;

Expand Down
142 changes: 2 additions & 140 deletions substrate/frame/support/src/storage/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,140 +27,6 @@ use sp_std::prelude::*;

use super::PrefixIterator;

/// Utility to iterate through raw items in storage.
pub struct StorageIterator<T> {
prefix: Vec<u8>,
previous_key: Vec<u8>,
drain: bool,
_phantom: ::sp_std::marker::PhantomData<T>,
}

impl<T> StorageIterator<T> {
/// Construct iterator to iterate over map items in `module` for the map called `item`.
#[deprecated(note = "Will be removed after July 2023; Please use the storage_iter or \
storage_iter_with_suffix functions instead")]
pub fn new(module: &[u8], item: &[u8]) -> Self {
#[allow(deprecated)]
Self::with_suffix(module, item, &[][..])
}

/// Construct iterator to iterate over map items in `module` for the map called `item`.
#[deprecated(note = "Will be removed after July 2023; Please use the storage_iter or \
storage_iter_with_suffix functions instead")]
pub fn with_suffix(module: &[u8], item: &[u8], suffix: &[u8]) -> Self {
let mut prefix = Vec::new();
let storage_prefix = storage_prefix(module, item);
prefix.extend_from_slice(&storage_prefix);
prefix.extend_from_slice(suffix);
let previous_key = prefix.clone();
Self { prefix, previous_key, drain: false, _phantom: Default::default() }
}

/// Mutate this iterator into a draining iterator; items iterated are removed from storage.
pub fn drain(mut self) -> Self {
self.drain = true;
self
}
}

impl<T: Decode + Sized> Iterator for StorageIterator<T> {
type Item = (Vec<u8>, T);

fn next(&mut self) -> Option<(Vec<u8>, T)> {
loop {
let maybe_next = sp_io::storage::next_key(&self.previous_key)
.filter(|n| n.starts_with(&self.prefix));
break match maybe_next {
Some(next) => {
self.previous_key = next.clone();
let maybe_value = frame_support::storage::unhashed::get::<T>(&next);
match maybe_value {
Some(value) => {
if self.drain {
frame_support::storage::unhashed::kill(&next);
}
Some((self.previous_key[self.prefix.len()..].to_vec(), value))
},
None => continue,
}
},
None => None,
}
}
}
}

/// Utility to iterate through raw items in storage.
pub struct StorageKeyIterator<K, T, H: ReversibleStorageHasher> {
prefix: Vec<u8>,
previous_key: Vec<u8>,
drain: bool,
_phantom: ::sp_std::marker::PhantomData<(K, T, H)>,
}

impl<K, T, H: ReversibleStorageHasher> StorageKeyIterator<K, T, H> {
/// Construct iterator to iterate over map items in `module` for the map called `item`.
#[deprecated(note = "Will be removed after July 2023; Please use the storage_key_iter or \
storage_key_iter_with_suffix functions instead")]
pub fn new(module: &[u8], item: &[u8]) -> Self {
#[allow(deprecated)]
Self::with_suffix(module, item, &[][..])
}

/// Construct iterator to iterate over map items in `module` for the map called `item`.
#[deprecated(note = "Will be removed after July 2023; Please use the storage_key_iter or \
storage_key_iter_with_suffix functions instead")]
pub fn with_suffix(module: &[u8], item: &[u8], suffix: &[u8]) -> Self {
let mut prefix = Vec::new();
let storage_prefix = storage_prefix(module, item);
prefix.extend_from_slice(&storage_prefix);
prefix.extend_from_slice(suffix);
let previous_key = prefix.clone();
Self { prefix, previous_key, drain: false, _phantom: Default::default() }
}

/// Mutate this iterator into a draining iterator; items iterated are removed from storage.
pub fn drain(mut self) -> Self {
self.drain = true;
self
}
}

impl<K: Decode + Sized, T: Decode + Sized, H: ReversibleStorageHasher> Iterator
for StorageKeyIterator<K, T, H>
{
type Item = (K, T);

fn next(&mut self) -> Option<(K, T)> {
loop {
let maybe_next = sp_io::storage::next_key(&self.previous_key)
.filter(|n| n.starts_with(&self.prefix));
break match maybe_next {
Some(next) => {
self.previous_key = next.clone();
let mut key_material = H::reverse(&next[self.prefix.len()..]);
match K::decode(&mut key_material) {
Ok(key) => {
let maybe_value = frame_support::storage::unhashed::get::<T>(&next);
match maybe_value {
Some(value) => {
if self.drain {
frame_support::storage::unhashed::kill(&next);
}
Some((key, value))
},
None => continue,
}
},
Err(_) => continue,
}
},
None => None,
}
}
}
}

/// Construct iterator to iterate over map items in `module` for the map called `item`.
pub fn storage_iter<T: Decode + Sized>(module: &[u8], item: &[u8]) -> PrefixIterator<(Vec<u8>, T)> {
storage_iter_with_suffix(module, item, &[][..])
Expand Down Expand Up @@ -254,11 +120,7 @@ pub fn put_storage_value<T: Encode>(module: &[u8], item: &[u8], hash: &[u8], val
/// `hash`.
#[deprecated = "Use `clear_storage_prefix` instead"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a deprecation string here in the same format as above with a fixed date please?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that can also be deleted, as even if it didn't have the deprecation date noted is already 16 months old

pub fn remove_storage_prefix(module: &[u8], item: &[u8], hash: &[u8]) {
let mut key = vec![0u8; 32 + hash.len()];
let storage_prefix = storage_prefix(module, item);
key[0..32].copy_from_slice(&storage_prefix);
key[32..].copy_from_slice(hash);
let _ = frame_support::storage::unhashed::clear_prefix(&key, None, None);
let _ = clear_storage_prefix(module, item, hash, None, None);
}

/// Attempt to remove all values under a storage prefix by the `module`, the map's `item` name and
Expand Down Expand Up @@ -288,7 +150,7 @@ pub fn clear_storage_prefix(
let storage_prefix = storage_prefix(module, item);
key[0..32].copy_from_slice(&storage_prefix);
key[32..].copy_from_slice(hash);
frame_support::storage::unhashed::clear_prefix(&key, maybe_limit, maybe_cursor)
unhashed::clear_prefix(&key, maybe_limit, maybe_cursor)
}

/// Take a particular item in storage by the `module`, the map's `item` name and the key `hash`.
Expand Down
2 changes: 0 additions & 2 deletions substrate/frame/support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ pub use tokens::{
};

mod members;
#[allow(deprecated)]
pub use members::{AllowAll, DenyAll, Filter};
pub use members::{
AsContains, ChangeMembers, Contains, ContainsLengthBound, ContainsPair, Everything,
EverythingBut, FromContainsPair, InitializeMembers, InsideBoth, IsInVec, Nothing,
Expand Down
23 changes: 0 additions & 23 deletions substrate/frame/support/src/traits/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,29 +172,6 @@ macro_rules! match_types {
() => {}
}

/// Create a type which implements the `Contains` trait for a particular type with syntax similar
/// to `matches!`.
#[macro_export]
#[deprecated = "Use `match_types!` instead"]
macro_rules! match_type {
($( $x:tt )*) => { $crate::match_types!( $( $x )* ); }
}

#[deprecated = "Use `Everything` instead"]
pub type AllowAll = Everything;
#[deprecated = "Use `Nothing` instead"]
pub type DenyAll = Nothing;
#[deprecated = "Use `Contains` instead"]
pub trait Filter<T> {
fn filter(t: &T) -> bool;
}
#[allow(deprecated)]
impl<T, C: Contains<T>> Filter<T> for C {
fn filter(t: &T) -> bool {
Self::contains(t)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
27 changes: 1 addition & 26 deletions substrate/frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,31 +1065,6 @@ impl<T: Config> Pallet<T> {
Ok(())
}

/// Increment the reference counter on an account.
#[deprecated = "Use `inc_consumers` instead"]
pub fn inc_ref(who: &T::AccountId) {
let _ = Self::inc_consumers(who);
}

/// Decrement the reference counter on an account. This *MUST* only be done once for every time
/// you called `inc_consumers` on `who`.
#[deprecated = "Use `dec_consumers` instead"]
pub fn dec_ref(who: &T::AccountId) {
let _ = Self::dec_consumers(who);
}

/// The number of outstanding references for the account `who`.
#[deprecated = "Use `consumers` instead"]
pub fn refs(who: &T::AccountId) -> RefCount {
Self::consumers(who)
}

/// True if the account has no outstanding references.
#[deprecated = "Use `!is_provider_required` instead"]
pub fn allow_death(who: &T::AccountId) -> bool {
!Self::is_provider_required(who)
}

/// Increment the provider reference counter on an account.
pub fn inc_providers(who: &T::AccountId) -> IncRefStatus {
Account::<T>::mutate(who, |a| {
Expand Down Expand Up @@ -1514,7 +1489,7 @@ impl<T: Config> Pallet<T> {
/// Should only be called if you know what you are doing and outside of the runtime block
/// execution else it can have a large impact on the PoV size of a block.
pub fn read_events_no_consensus(
) -> impl sp_std::iter::Iterator<Item = Box<EventRecord<T::RuntimeEvent, T::Hash>>> {
) -> impl Iterator<Item = Box<EventRecord<T::RuntimeEvent, T::Hash>>> {
Events::<T>::stream_iter()
}

Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/utility/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ use crate as utility;
use frame_support::{
assert_err_ignore_postinfo, assert_noop, assert_ok,
dispatch::{DispatchErrorWithPostInfo, Pays},
error::BadOrigin,
parameter_types, storage,
traits::{ConstU32, ConstU64, Contains},
weights::Weight,
};
use pallet_collective::{EnsureProportionAtLeast, Instance1};
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, Dispatchable, Hash, IdentityLookup},
traits::{BadOrigin, BlakeTwo256, Dispatchable, Hash, IdentityLookup},
BuildStorage, DispatchError, TokenError,
};

Expand Down
Loading