Skip to content

Commit

Permalink
Fix nostd build of several crates (#4060)
Browse files Browse the repository at this point in the history
Preparation for #3935

Changes:
- Add some `default-features = false` for the case that a crate and that
dependency both support nostd builds.
- Shuffle files around of some benchmarking-only crates. These
conditionally disabled the `cfg_attr` for nostd and pulled in libstd.
Example [here](ggwpez/zepter#95). The actual
logic is moved into a `inner.rs` to preserve nostd capability of the
crate in case the benchmarking feature is disabled.
- Add some `use sp_std::vec` where needed.
- Remove some `optional = true` in cases where it was not optional.
- Removed one superfluous `cfg_attr(not(feature = "std"), no_std..`.

All in all this should be logical no-op.

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez committed Apr 17, 2024
1 parent bfbf7f5 commit 7a2c9d4
Show file tree
Hide file tree
Showing 36 changed files with 1,800 additions and 1,601 deletions.
42 changes: 42 additions & 0 deletions cumulus/pallets/session-benchmarking/src/inner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Benchmarking setup for pallet-session.

use sp_std::{prelude::*, vec};

use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_system::RawOrigin;
use pallet_session::*;
use parity_scale_codec::Decode;
pub struct Pallet<T: Config>(pallet_session::Pallet<T>);
pub trait Config: pallet_session::Config {}

benchmarks! {
set_keys {
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::inc_providers(&caller);
let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap();
let proof: Vec<u8> = vec![0,1,2,3];
}: _(RawOrigin::Signed(caller), keys, proof)

purge_keys {
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::inc_providers(&caller);
let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap();
let proof: Vec<u8> = vec![0,1,2,3];
let _t = pallet_session::Pallet::<T>::set_keys(RawOrigin::Signed(caller.clone()).into(), keys, proof);
}: _(RawOrigin::Signed(caller))
}
34 changes: 9 additions & 25 deletions cumulus/pallets/session-benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -13,31 +15,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Benchmarking setup for pallet-session
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg(feature = "runtime-benchmarks")]
use sp_std::{prelude::*, vec};
//! Benchmarks for the Session Pallet.
// This is separated into its own crate due to cyclic dependency issues.

use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_system::RawOrigin;
use pallet_session::*;
use parity_scale_codec::Decode;
pub struct Pallet<T: Config>(pallet_session::Pallet<T>);
pub trait Config: pallet_session::Config {}
#![cfg_attr(not(feature = "std"), no_std)]

benchmarks! {
set_keys {
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::inc_providers(&caller);
let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap();
let proof: Vec<u8> = vec![0,1,2,3];
}: _(RawOrigin::Signed(caller), keys, proof)
#[cfg(feature = "runtime-benchmarks")]
pub mod inner;

purge_keys {
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::inc_providers(&caller);
let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap();
let proof: Vec<u8> = vec![0,1,2,3];
let _t = pallet_session::Pallet::<T>::set_keys(RawOrigin::Signed(caller.clone()).into(), keys, proof);
}: _(RawOrigin::Signed(caller))
}
#[cfg(feature = "runtime-benchmarks")]
pub use inner::*;
10 changes: 1 addition & 9 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pallet-nfts = { path = "../../../../../substrate/frame/nfts", default-features =
pallet-nfts-runtime-api = { path = "../../../../../substrate/frame/nfts/runtime-api", default-features = false }
pallet-proxy = { path = "../../../../../substrate/frame/proxy", default-features = false }
pallet-session = { path = "../../../../../substrate/frame/session", default-features = false }
pallet-state-trie-migration = { path = "../../../../../substrate/frame/state-trie-migration", default-features = false, optional = true }
pallet-state-trie-migration = { path = "../../../../../substrate/frame/state-trie-migration", default-features = false }
pallet-timestamp = { path = "../../../../../substrate/frame/timestamp", default-features = false }
pallet-transaction-payment = { path = "../../../../../substrate/frame/transaction-payment", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { path = "../../../../../substrate/frame/transaction-payment/rpc/runtime-api", default-features = false }
Expand Down Expand Up @@ -102,14 +102,6 @@ substrate-wasm-builder = { path = "../../../../../substrate/utils/wasm-builder",

[features]
default = ["std"]
# When enabled the `state_version` is set to `1`.
# This means that the chain will start using the new state format. The migration is lazy, so
# it requires to write a storage value to use the new state format. To migrate all the other
# storage values that aren't touched the state migration pallet is added as well.
# This pallet will migrate the entire state, controlled through some account.
#
# This feature should be removed when the main-net will be migrated.
state-trie-version-1 = ["pallet-state-trie-migration"]
runtime-benchmarks = [
"assets-common/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",
Expand Down
19 changes: 0 additions & 19 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ impl_opaque_keys! {
}
}

#[cfg(feature = "state-trie-version-1")]
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("statemine"),
Expand All @@ -120,19 +119,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
state_version: 1,
};

#[cfg(not(feature = "state-trie-version-1"))]
#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("statemine"),
impl_name: create_runtime_str!("statemine"),
authoring_version: 1,
spec_version: 1_010_000,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 14,
state_version: 0,
};

/// The version information used to identify this runtime when compiled natively.
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
Expand Down Expand Up @@ -953,7 +939,6 @@ construct_runtime!(
PoolAssets: pallet_assets::<Instance3> = 55,
AssetConversion: pallet_asset_conversion = 56,

#[cfg(feature = "state-trie-version-1")]
StateTrieMigration: pallet_state_trie_migration = 70,

// TODO: the pallet instance should be removed once all pools have migrated
Expand Down Expand Up @@ -1695,15 +1680,13 @@ cumulus_pallet_parachain_system::register_validate_block! {
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}

#[cfg(feature = "state-trie-version-1")]
parameter_types! {
// The deposit configuration for the singed migration. Specially if you want to allow any signed account to do the migration (see `SignedFilter`, these deposits should be high)
pub const MigrationSignedDepositPerItem: Balance = CENTS;
pub const MigrationSignedDepositBase: Balance = 2_000 * CENTS;
pub const MigrationMaxKeyLen: u32 = 512;
}

#[cfg(feature = "state-trie-version-1")]
impl pallet_state_trie_migration::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
Expand All @@ -1721,13 +1704,11 @@ impl pallet_state_trie_migration::Config for Runtime {
type MaxKeyLen = MigrationMaxKeyLen;
}

#[cfg(feature = "state-trie-version-1")]
frame_support::ord_parameter_types! {
pub const MigController: AccountId = AccountId::from(hex_literal::hex!("8458ed39dc4b6f6c7255f7bc42be50c2967db126357c999d44e12ca7ac80dc52"));
pub const RootMigController: AccountId = AccountId::from(hex_literal::hex!("8458ed39dc4b6f6c7255f7bc42be50c2967db126357c999d44e12ca7ac80dc52"));
}

#[cfg(feature = "state-trie-version-1")]
#[test]
fn ensure_key_ss58() {
use frame_support::traits::SortedMembers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ frame-system-rpc-runtime-api = { path = "../../../../../substrate/frame/system/r
frame-system-benchmarking = { path = "../../../../../substrate/frame/system/benchmarking", default-features = false, optional = true }
frame-try-runtime = { path = "../../../../../substrate/frame/try-runtime", default-features = false, optional = true }
pallet-aura = { path = "../../../../../substrate/frame/aura", default-features = false }
pallet-glutton = { path = "../../../../../substrate/frame/glutton", default-features = false, optional = true }
pallet-sudo = { path = "../../../../../substrate/frame/sudo", default-features = false, optional = true }
pallet-glutton = { path = "../../../../../substrate/frame/glutton", default-features = false }
pallet-sudo = { path = "../../../../../substrate/frame/sudo", default-features = false }
pallet-timestamp = { path = "../../../../../substrate/frame/timestamp", default-features = false }
sp-api = { path = "../../../../../substrate/primitives/api", default-features = false }
sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false }
Expand Down
6 changes: 4 additions & 2 deletions cumulus/primitives/parachain-inherent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ scale-info = { version = "2.11.1", default-features = false, features = ["derive
# Substrate
sp-core = { path = "../../../substrate/primitives/core", default-features = false }
sp-inherents = { path = "../../../substrate/primitives/inherents", default-features = false }
sp-runtime = { path = "../../../substrate/primitives/runtime", optional = true }
sp-state-machine = { path = "../../../substrate/primitives/state-machine", optional = true }
sp-runtime = { path = "../../../substrate/primitives/runtime", optional = true, default-features = false }
sp-state-machine = { path = "../../../substrate/primitives/state-machine", optional = true, default-features = false }
sp-std = { path = "../../../substrate/primitives/std", default-features = false }
sp-trie = { path = "../../../substrate/primitives/trie", default-features = false }

Expand All @@ -34,6 +34,8 @@ std = [
"scale-info/std",
"sp-core/std",
"sp-inherents/std",
"sp-runtime?/std",
"sp-state-machine?/std",
"sp-std/std",
"sp-trie/std",
]
3 changes: 2 additions & 1 deletion polkadot/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sp-arithmetic = { path = "../../substrate/primitives/arithmetic", default-featur
sp-authority-discovery = { path = "../../substrate/primitives/authority-discovery", default-features = false, features = ["serde"] }
sp-consensus-slots = { path = "../../substrate/primitives/consensus/slots", default-features = false, features = ["serde"] }
sp-io = { path = "../../substrate/primitives/io", default-features = false }
sp-keystore = { path = "../../substrate/primitives/keystore", optional = true }
sp-keystore = { path = "../../substrate/primitives/keystore", optional = true, default-features = false }
sp-staking = { path = "../../substrate/primitives/staking", default-features = false, features = ["serde"] }
sp-std = { package = "sp-std", path = "../../substrate/primitives/std", default-features = false }

Expand All @@ -53,6 +53,7 @@ std = [
"sp-consensus-slots/std",
"sp-io/std",
"sp-keystore",
"sp-keystore?/std",
"sp-staking/std",
"sp-std/std",
]
Expand Down
3 changes: 2 additions & 1 deletion polkadot/runtime/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sp-runtime = { path = "../../../substrate/primitives/runtime", default-features
sp-session = { path = "../../../substrate/primitives/session", default-features = false }
sp-staking = { path = "../../../substrate/primitives/staking", default-features = false, features = ["serde"] }
sp-core = { path = "../../../substrate/primitives/core", default-features = false, features = ["serde"] }
sp-keystore = { path = "../../../substrate/primitives/keystore", optional = true }
sp-keystore = { path = "../../../substrate/primitives/keystore", optional = true, default-features = false }
sp-application-crypto = { path = "../../../substrate/primitives/application-crypto", default-features = false, optional = true }
sp-tracing = { path = "../../../substrate/primitives/tracing", default-features = false, optional = true }
sp-arithmetic = { path = "../../../substrate/primitives/arithmetic", default-features = false }
Expand Down Expand Up @@ -108,6 +108,7 @@ std = [
"sp-core/std",
"sp-io/std",
"sp-keystore",
"sp-keystore?/std",
"sp-runtime/std",
"sp-session/std",
"sp-staking/std",
Expand Down
1 change: 0 additions & 1 deletion polkadot/xcm/xcm-executor/integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

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

use codec::Encode;
Expand Down
54 changes: 54 additions & 0 deletions prdoc/pr_4060.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
title: "Fix nostd build of several crates"

doc:
- audience: Runtime Dev
description: |
Fixes feature and dependency configuration of several crate. This should allow for better no-std build capabilities.

crates:
- name: cumulus-pallet-session-benchmarking
bump: patch
- name: asset-hub-rococo-runtime
bump: patch
- name: glutton-westend-runtime
bump: patch
- name: cumulus-primitives-parachain-inherent
bump: patch
- name: polkadot-primitives
bump: patch
- name: polkadot-runtime-parachains
bump: patch
- name: xcm-executor-integration-tests
bump: patch
- name: pallet-atomic-swap
bump: patch
- name: pallet-election-provider-support-benchmarking
bump: patch
- name: pallet-dev-mode
bump: patch
- name: pallet-example-offchain-worker
bump: patch
- name: pallet-indices
bump: patch
- name: pallet-nomination-pools
bump: patch
- name: pallet-nomination-pools-benchmarking
bump: patch
- name: pallet-offences-benchmarking
bump: patch
- name: pallet-root-offences
bump: patch
- name: pallet-session-benchmarking
bump: patch
- name: frame-system-benchmarking
bump: patch
- name: sp-consensus-babe
bump: patch
- name: sp-consensus-babe
bump: patch
- name: sp-core
bump: patch
- name: sp-session
bump: patch
- name: sp-transaction-storage-proof
bump: patch
2 changes: 1 addition & 1 deletion substrate/frame/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
license = "Apache-2.0"
homepage = "paritytech.github.io"
repository.workspace = true
description = "The single package to get you started with building frame pallets and runtimes"
description = "Experimental: The single package to get you started with building frame pallets and runtimes"
publish = false

[lints]
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/atomic-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use frame_system::pallet_prelude::BlockNumberFor;
use scale_info::TypeInfo;
use sp_io::hashing::blake2_256;
use sp_runtime::RuntimeDebug;
use sp_std::vec::Vec;

/// Pending atomic swap operation.
#[derive(Clone, Eq, PartialEq, RuntimeDebugNoBound, Encode, Decode, TypeInfo, MaxEncodedLen)]
Expand Down

0 comments on commit 7a2c9d4

Please sign in to comment.