Skip to content

Commit

Permalink
Remove most all usage of sp-std (paritytech#5010)
Browse files Browse the repository at this point in the history
This should remove nearly all usage of `sp-std` except:
- bridge and bridge-hubs
- a few of frames re-export `sp-std`, keep them for now
- there is a usage of `sp_std::Writer`, I don't have an idea how to move
it

Please review proc-macro carefully. I'm not sure I'm doing it the right
way.

Note: need `/bot fmt`

---------

Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: command-bot <>
  • Loading branch information
2 people authored and jpserrat committed Jul 18, 2024
1 parent 79e9315 commit 5016aac
Show file tree
Hide file tree
Showing 825 changed files with 1,835 additions and 1,938 deletions.
159 changes: 0 additions & 159 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion cumulus/client/parachain-inherent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ sp-crypto-hashing = { workspace = true, default-features = true }
sp-inherents = { workspace = true, default-features = true }
sp-runtime = { workspace = true, default-features = true }
sp-state-machine = { workspace = true, default-features = true }
sp-std = { workspace = true, default-features = true }
sp-storage = { workspace = true, default-features = true }
sp-trie = { workspace = true, default-features = true }

Expand Down
4 changes: 2 additions & 2 deletions cumulus/client/relay-chain-inprocess-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.

use std::{pin::Pin, sync::Arc, time::Duration};
use std::{collections::btree_map::BTreeMap, pin::Pin, sync::Arc, time::Duration};

use async_trait::async_trait;
use cumulus_primitives_core::{
Expand All @@ -38,7 +38,7 @@ use sc_client_api::{
use sc_telemetry::TelemetryWorkerHandle;
use sp_api::ProvideRuntimeApi;
use sp_consensus::SyncOracle;
use sp_core::{sp_std::collections::btree_map::BTreeMap, Pair};
use sp_core::Pair;
use sp_state_machine::{Backend as StateBackend, StorageValue};

/// The timeout in seconds after that the waiting for a block should be aborted.
Expand Down
3 changes: 1 addition & 2 deletions cumulus/client/relay-chain-rpc-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ use futures::{FutureExt, Stream, StreamExt};
use polkadot_overseer::Handle;

use sc_client_api::StorageProof;
use sp_core::sp_std::collections::btree_map::BTreeMap;
use sp_state_machine::StorageValue;
use sp_storage::StorageKey;
use sp_version::RuntimeVersion;
use std::pin::Pin;
use std::{collections::btree_map::BTreeMap, pin::Pin};

use cumulus_primitives_core::relay_chain::BlockId;
pub use url::Url;
Expand Down
3 changes: 1 addition & 2 deletions cumulus/client/relay-chain-rpc-interface/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use jsonrpsee::{
};
use serde::de::DeserializeOwned;
use serde_json::Value as JsonValue;
use std::collections::VecDeque;
use std::collections::{btree_map::BTreeMap, VecDeque};
use tokio::sync::mpsc::Sender as TokioSender;

use codec::{Decode, Encode};
Expand All @@ -47,7 +47,6 @@ use sc_client_api::StorageData;
use sc_rpc_api::{state::ReadProof, system::Health};
use sc_service::TaskManager;
use sp_consensus_babe::Epoch;
use sp_core::sp_std::collections::btree_map::BTreeMap;
use sp_storage::StorageKey;
use sp_version::RuntimeVersion;

Expand Down
2 changes: 0 additions & 2 deletions cumulus/pallets/aura-ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pallet-timestamp = { workspace = true }
sp-application-crypto = { workspace = true }
sp-consensus-aura = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

# Cumulus
cumulus-pallet-parachain-system = { workspace = true }
Expand All @@ -44,7 +43,6 @@ std = [
"sp-application-crypto/std",
"sp-consensus-aura/std",
"sp-runtime/std",
"sp-std/std",
]
try-runtime = [
"cumulus-pallet-parachain-system/try-runtime",
Expand Down
4 changes: 2 additions & 2 deletions cumulus/pallets/aura-ext/src/consensus_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
//! The velocity `V` refers to the rate of block processing by the relay chain.

use super::{pallet, Aura};
use core::{marker::PhantomData, num::NonZeroU32};
use cumulus_pallet_parachain_system::{
self as parachain_system,
consensus_hook::{ConsensusHook, UnincludedSegmentCapacity},
relay_state_snapshot::RelayChainStateProof,
};
use frame_support::pallet_prelude::*;
use sp_consensus_aura::{Slot, SlotDuration};
use sp_std::{marker::PhantomData, num::NonZeroU32};

/// A consensus hook for a fixed block processing velocity and unincluded segment capacity.
///
Expand Down Expand Up @@ -84,7 +84,7 @@ where

(
weight,
NonZeroU32::new(sp_std::cmp::max(C, 1))
NonZeroU32::new(core::cmp::max(C, 1))
.expect("1 is the minimum value and non-zero; qed")
.into(),
)
Expand Down
4 changes: 2 additions & 2 deletions cumulus/pallets/aura-ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub mod pallet {
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
#[serde(skip)]
pub _config: sp_std::marker::PhantomData<T>,
pub _config: core::marker::PhantomData<T>,
}

#[pallet::genesis_build]
Expand All @@ -125,7 +125,7 @@ pub mod pallet {
///
/// When executing the block it will verify the block seal to ensure that the correct author created
/// the block.
pub struct BlockExecutor<T, I>(sp_std::marker::PhantomData<(T, I)>);
pub struct BlockExecutor<T, I>(core::marker::PhantomData<(T, I)>);

impl<Block, T, I> ExecuteBlock<Block> for BlockExecutor<T, I>
where
Expand Down
2 changes: 0 additions & 2 deletions cumulus/pallets/collator-selection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ codec = { features = ["derive"], workspace = true }
rand = { features = ["std_rng"], workspace = true }
scale-info = { features = ["derive"], workspace = true }

sp-std = { workspace = true }
sp-runtime = { workspace = true }
sp-staking = { workspace = true }
frame-support = { workspace = true }
Expand Down Expand Up @@ -65,7 +64,6 @@ std = [
"scale-info/std",
"sp-runtime/std",
"sp-staking/std",
"sp-std/std",
]

try-runtime = [
Expand Down
3 changes: 2 additions & 1 deletion cumulus/pallets/collator-selection/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ use super::*;

#[allow(unused)]
use crate::Pallet as CollatorSelection;
use alloc::vec::Vec;
use codec::Decode;
use core::cmp;
use frame_benchmarking::{account, v2::*, whitelisted_caller, BenchmarkError};
use frame_support::traits::{Currency, EnsureOrigin, Get, ReservableCurrency};
use frame_system::{pallet_prelude::BlockNumberFor, EventRecord, RawOrigin};
use pallet_authorship::EventHandler;
use pallet_session::{self as session, SessionManager};
use sp_std::{cmp, prelude::*};

pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
Expand Down
6 changes: 4 additions & 2 deletions cumulus/pallets/collator-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@

#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

use core::marker::PhantomData;
use frame_support::traits::TypedGet;
pub use pallet::*;
Expand All @@ -101,6 +103,7 @@ const LOG_TARGET: &str = "runtime::collator-selection";
#[frame_support::pallet]
pub mod pallet {
pub use crate::weights::WeightInfo;
use alloc::vec::Vec;
use core::ops::Div;
use frame_support::{
dispatch::{DispatchClass, DispatchResultWithPostInfo},
Expand All @@ -118,7 +121,6 @@ pub mod pallet {
RuntimeDebug,
};
use sp_staking::SessionIndex;
use sp_std::vec::Vec;

/// The in-code storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);
Expand Down Expand Up @@ -244,7 +246,7 @@ pub mod pallet {
let duplicate_invulnerables = self
.invulnerables
.iter()
.collect::<sp_std::collections::btree_set::BTreeSet<_>>();
.collect::<alloc::collections::btree_set::BTreeSet<_>>();
assert!(
duplicate_invulnerables.len() == self.invulnerables.len(),
"duplicate invulnerables in genesis."
Expand Down
10 changes: 4 additions & 6 deletions cumulus/pallets/collator-selection/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
//! A module that is responsible for migration of storage for Collator Selection.

use super::*;
#[cfg(feature = "try-runtime")]
use alloc::vec::Vec;
use frame_support::traits::{OnRuntimeUpgrade, UncheckedOnRuntimeUpgrade};
use log;

Expand All @@ -29,8 +31,6 @@ pub mod v2 {
traits::{Currency, ReservableCurrency},
};
use sp_runtime::traits::{Saturating, Zero};
#[cfg(feature = "try-runtime")]
use sp_std::vec::Vec;

/// [`UncheckedMigrationToV2`] wrapped in a
/// [`VersionedMigration`](frame_support::migrations::VersionedMigration), ensuring the
Expand All @@ -51,7 +51,7 @@ pub mod v2 {
>;

/// Migrate to V2.
pub struct UncheckedMigrationToV2<T>(sp_std::marker::PhantomData<T>);
pub struct UncheckedMigrationToV2<T>(PhantomData<T>);
impl<T: Config + pallet_balances::Config> UncheckedOnRuntimeUpgrade for UncheckedMigrationToV2<T> {
fn on_runtime_upgrade() -> Weight {
let mut weight = Weight::zero();
Expand Down Expand Up @@ -123,10 +123,8 @@ pub mod v2 {
pub mod v1 {
use super::*;
use frame_support::pallet_prelude::*;
#[cfg(feature = "try-runtime")]
use sp_std::prelude::*;

pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>);
pub struct MigrateToV1<T>(PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
fn on_runtime_upgrade() -> Weight {
let on_chain_version = Pallet::<T>::on_chain_storage_version();
Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/collator-selection/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#![allow(unused_parens)]
#![allow(unused_imports)]

use core::marker::PhantomData;
use frame_support::{
traits::Get,
weights::{constants::RocksDbWeight, Weight},
};
use sp_std::marker::PhantomData;

// The weight info trait for `pallet_collator_selection`.
pub trait WeightInfo {
Expand Down
2 changes: 0 additions & 2 deletions cumulus/pallets/dmp-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ scale-info = { features = ["derive"], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-std = { workspace = true }
sp-runtime = { workspace = true }
sp-io = { workspace = true }

Expand All @@ -48,7 +47,6 @@ std = [
"scale-info/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"xcm/std",
]

Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/dmp-queue/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

use crate::*;

use alloc::vec;
use frame_benchmarking::v2::*;
use frame_support::{pallet_prelude::*, traits::Hooks};
use sp_std::vec;

#[benchmarks]
mod benchmarks {
Expand Down
2 changes: 2 additions & 0 deletions cumulus/pallets/dmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(deprecated)] // The pallet itself is deprecated.

extern crate alloc;

use migration::*;
pub use pallet::*;

Expand Down
2 changes: 1 addition & 1 deletion cumulus/pallets/dmp-queue/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
//! Migrates the storage from the previously deleted DMP pallet.

use crate::*;
use alloc::vec::Vec;
use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber;
use frame_support::{pallet_prelude::*, storage_alias, traits::HandleMessage};
use sp_std::vec::Vec;

pub(crate) const LOG: &str = "runtime::dmp-queue-export-xcms";

Expand Down
4 changes: 2 additions & 2 deletions cumulus/pallets/parachain-system/proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ pub fn register_validate_block(input: proc_macro::TokenStream) -> proc_macro::To
#[no_mangle]
unsafe fn validate_block(arguments: *mut u8, arguments_len: usize) -> u64 {
// We convert the `arguments` into a boxed slice and then into `Bytes`.
let args = #crate_::validate_block::sp_std::boxed::Box::from_raw(
#crate_::validate_block::sp_std::slice::from_raw_parts_mut(
let args = #crate_::validate_block::Box::from_raw(
#crate_::validate_block::slice::from_raw_parts_mut(
arguments,
arguments_len,
)
Expand Down
4 changes: 2 additions & 2 deletions cumulus/pallets/parachain-system/src/consensus_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
//! of parachain blocks ready to submit to the relay chain, as well as some basic implementations.

use super::relay_state_snapshot::RelayChainStateProof;
use core::num::NonZeroU32;
use frame_support::weights::Weight;
use sp_std::num::NonZeroU32;

/// The possible capacity of the unincluded segment.
#[derive(Clone)]
Expand Down Expand Up @@ -95,7 +95,7 @@ impl<const N: u32> ConsensusHook for FixedCapacityUnincludedSegment<N> {
fn on_state_proof(_state_proof: &RelayChainStateProof) -> (Weight, UnincludedSegmentCapacity) {
(
Weight::zero(),
NonZeroU32::new(sp_std::cmp::max(N, 1))
NonZeroU32::new(core::cmp::max(N, 1))
.expect("1 is the minimum value and non-zero; qed")
.into(),
)
Expand Down
13 changes: 8 additions & 5 deletions cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
//!
//! Users must ensure that they register this pallet as an inherent provider.

extern crate alloc;

use alloc::{collections::btree_map::BTreeMap, vec, vec::Vec};
use codec::{Decode, Encode};
use core::cmp;
use cumulus_primitives_core::{
relay_chain, AbridgedHostConfiguration, ChannelInfo, ChannelStatus, CollationInfo,
GetChannelInfo, InboundDownwardMessage, InboundHrmpMessage, ListChannelInfos, MessageSendError,
Expand All @@ -54,7 +58,6 @@ use sp_runtime::{
},
BoundedSlice, FixedU128, RuntimeDebug, Saturating,
};
use sp_std::{cmp, collections::btree_map::BTreeMap, prelude::*};
use xcm::{latest::XcmHash, VersionedLocation, VersionedXcm};
use xcm_builder::InspectMessageQueues;

Expand Down Expand Up @@ -938,7 +941,7 @@ pub mod pallet {
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
#[serde(skip)]
pub _config: sp_std::marker::PhantomData<T>,
pub _config: core::marker::PhantomData<T>,
}

#[pallet::genesis_build]
Expand Down Expand Up @@ -1530,7 +1533,7 @@ impl<T: Config> Pallet<T> {
}

/// Type that implements `SetCode`.
pub struct ParachainSetCode<T>(sp_std::marker::PhantomData<T>);
pub struct ParachainSetCode<T>(core::marker::PhantomData<T>);
impl<T: Config> frame_system::SetCode<T> for ParachainSetCode<T> {
fn set_code(code: Vec<u8>) -> DispatchResult {
Pallet::<T>::schedule_code_upgrade(code)
Expand Down Expand Up @@ -1645,7 +1648,7 @@ pub trait CheckInherents<Block: BlockT> {

/// Struct that always returns `Ok` on inherents check, needed for backwards-compatibility.
#[doc(hidden)]
pub struct DummyCheckInherents<Block>(sp_std::marker::PhantomData<Block>);
pub struct DummyCheckInherents<Block>(core::marker::PhantomData<Block>);

#[allow(deprecated)]
impl<Block: BlockT> CheckInherents<Block> for DummyCheckInherents<Block> {
Expand Down Expand Up @@ -1718,7 +1721,7 @@ pub type RelaychainBlockNumberProvider<T> = RelaychainDataProvider<T>;
/// of [`RelayChainState`].
/// - [`current_block_number`](Self::current_block_number): Will return
/// [`Pallet::last_relay_block_number()`].
pub struct RelaychainDataProvider<T>(sp_std::marker::PhantomData<T>);
pub struct RelaychainDataProvider<T>(core::marker::PhantomData<T>);

impl<T: Config> BlockNumberProvider for RelaychainDataProvider<T> {
type BlockNumber = relay_chain::BlockNumber;
Expand Down
3 changes: 2 additions & 1 deletion cumulus/pallets/parachain-system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

use super::*;

use alloc::collections::vec_deque::VecDeque;
use codec::Encode;
use core::num::NonZeroU32;
use cumulus_primitives_core::{
relay_chain::BlockNumber as RelayBlockNumber, AggregateMessageOrigin, InboundDownwardMessage,
InboundHrmpMessage, PersistedValidationData,
Expand All @@ -37,7 +39,6 @@ use frame_support::{
};
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use sp_runtime::{traits::BlakeTwo256, BuildStorage};
use sp_std::{collections::vec_deque::VecDeque, num::NonZeroU32};
use sp_version::RuntimeVersion;
use std::cell::RefCell;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

//! Relay chain state proof provides means for accessing part of relay chain storage for reads.

use alloc::vec::Vec;
use codec::{Decode, Encode};
use cumulus_primitives_core::{
relay_chain, AbridgedHostConfiguration, AbridgedHrmpChannel, ParaId,
};
use scale_info::TypeInfo;
use sp_runtime::traits::HashingFor;
use sp_state_machine::{Backend, TrieBackend, TrieBackendBuilder};
use sp_std::vec::Vec;
use sp_trie::{HashDBT, MemoryDB, StorageProof, EMPTY_PREFIX};

/// The capacity of the upward message queue of a parachain on the relay chain.
Expand Down
Loading

0 comments on commit 5016aac

Please sign in to comment.