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

Fix nostd build of several crates #4060

Merged
merged 23 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
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::*;
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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 }
Copy link
Member Author

Choose a reason for hiding this comment

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

This should still be gated by the construct_runtime! feature gate. But i think that is not actually working, otherwise this change would not be needed 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

What?

Generally we don't need this anymore and the state migration should already have been finished.

Copy link
Member Author

@ggwpez ggwpez Apr 15, 2024

Choose a reason for hiding this comment

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

It is still deployed though, will double-check and remove it then.

Copy link
Member Author

Choose a reason for hiding this comment

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

Uhf, did we really genesis the asset-hub-rococo with state_version 0?
I just queried Core::version of the 1.1 runtime and it returns state_version=0...

Looks like it was copy&pasted from AHK. @cheme can you double-check please?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ouch https://github.com/polkadot-fellows/runtimes/blob/31ba26287ec752574244f0d690167f7ae8430c8b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs#L153 . (kusuma is fine).
Statemint on rococo (I guess it is now assethub, not sure) was migrated IIRC or was it only on westend cc @PierreBesson ?

Copy link
Member Author

@ggwpez ggwpez Apr 16, 2024

Choose a reason for hiding this comment

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

I meant it here for the Asset-hub-rococo:

#[cfg(feature = "state-trie-version-1")]

Not sure, since when i queried the runtime api it returned version 0. Maybe we can check with the RPC but the public node does not support it.
PS: Can you maybe create an issue to track the migration of the different runtimes? Or it already exists?

Copy link
Contributor

Choose a reason for hiding this comment

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

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 @@ -108,7 +108,7 @@ default = ["std"]
# 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"]
state-trie-version-1 = [ ]
runtime-benchmarks = [
"assets-common/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",
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 @@ -36,4 +36,6 @@ std = [
"sp-inherents/std",
"sp-std/std",
"sp-trie/std",
"sp-runtime?/std",
"sp-state-machine?/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 Down Expand Up @@ -55,6 +55,7 @@ std = [
"sp-keystore",
"sp-staking/std",
"sp-std/std",
"sp-keystore?/std"
]
runtime-benchmarks = [
"polkadot-parachain-primitives/runtime-benchmarks",
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 @@ -114,6 +114,7 @@ std = [
"sp-std/std",
"xcm-executor/std",
"xcm/std",
"sp-keystore?/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
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
56 changes: 56 additions & 0 deletions prdoc/pr_4060.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
- 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-contracts
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
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
2 changes: 1 addition & 1 deletion substrate/frame/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ frame-benchmarking = { path = "../benchmarking", default-features = false, optio
frame-support = { path = "../support", default-features = false }
frame-system = { path = "../system", default-features = false }
pallet-balances = { path = "../balances", default-features = false, optional = true }
pallet-contracts-uapi = { path = "uapi" }
pallet-contracts-uapi = { path = "uapi", default-features = false, features = ["scale"] }
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
pallet-contracts-proc-macro = { path = "proc-macro" }
sp-api = { path = "../../primitives/api", default-features = false }
sp-core = { path = "../../primitives/core", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// This file is part of Substrate.

// 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.

//! Election provider support pallet benchmarking.
//! This is separated into its own crate to avoid bloating the size of the runtime.

use codec::Decode;
use frame_benchmarking::v1::benchmarks;
use frame_election_provider_support::{NposSolver, PhragMMS, SequentialPhragmen};
use sp_std::vec::Vec;

pub struct Pallet<T: Config>(frame_system::Pallet<T>);
pub trait Config: frame_system::Config {}

const VOTERS: [u32; 2] = [1_000, 2_000];
const TARGETS: [u32; 2] = [500, 1_000];
const VOTES_PER_VOTER: [u32; 2] = [5, 16];

const SEED: u32 = 999;
fn set_up_voters_targets<AccountId: Decode + Clone>(
voters_len: u32,
targets_len: u32,
degree: usize,
) -> (Vec<(AccountId, u64, impl IntoIterator<Item = AccountId>)>, Vec<AccountId>) {
// fill targets.
let mut targets = (0..targets_len)
.map(|i| frame_benchmarking::account::<AccountId>("Target", i, SEED))
.collect::<Vec<_>>();
assert!(targets.len() > degree, "we should always have enough voters to fill");
targets.truncate(degree);

// fill voters.
let voters = (0..voters_len)
.map(|i| {
let voter = frame_benchmarking::account::<AccountId>("Voter", i, SEED);
(voter, 1_000, targets.clone())
})
.collect::<Vec<_>>();

(voters, targets)
}

benchmarks! {
phragmen {
// number of votes in snapshot.
let v in (VOTERS[0]) .. VOTERS[1];
// number of targets in snapshot.
let t in (TARGETS[0]) .. TARGETS[1];
// number of votes per voter (ie the degree).
let d in (VOTES_PER_VOTER[0]) .. VOTES_PER_VOTER[1];

let (voters, targets) = set_up_voters_targets::<T::AccountId>(v, t, d as usize);
}: {
assert!(
SequentialPhragmen::<T::AccountId, sp_runtime::Perbill>
::solve(d as usize, targets, voters).is_ok()
);
}

phragmms {
// number of votes in snapshot.
let v in (VOTERS[0]) .. VOTERS[1];
// number of targets in snapshot.
let t in (TARGETS[0]) .. TARGETS[1];
// number of votes per voter (ie the degree).
let d in (VOTES_PER_VOTER[0]) .. VOTES_PER_VOTER[1];

let (voters, targets) = set_up_voters_targets::<T::AccountId>(v, t, d as usize);
}: {
assert!(
PhragMMS::<T::AccountId, sp_runtime::Perbill>
::solve(d as usize, targets, voters).is_ok()
);
}
}
Loading
Loading