Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 48982ae

Browse files
Serialize/Deserialize trait implemented in no-std for numerous types (#7312)
* ParaId: Serialize/Deserialize trait implemented in no-std * Serialize/Deserialize trait implemented in no-std for more types * serde in deps enabled * fix * missing types added * update lockfile for {"substrate"} * ".git/.scripts/commands/fmt/fmt.sh" --------- Co-authored-by: parity-processbot <>
1 parent 26b4a21 commit 48982ae

File tree

16 files changed

+359
-265
lines changed

16 files changed

+359
-265
lines changed

Cargo.lock

Lines changed: 183 additions & 183 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

parachain/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ version.workspace = true
1010
# this crate for WASM. This is critical to avoid forcing all parachain WASM into implementing
1111
# various unnecessary Substrate-specific endpoints.
1212
parity-scale-codec = { version = "3.4.0", default-features = false, features = [ "derive" ] }
13-
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
13+
scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] }
1414
sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
15-
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
16-
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
15+
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, features = ["serde"] }
16+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, features = ["serde"] }
1717
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
1818
polkadot-core-primitives = { path = "../core-primitives", default-features = false }
1919
derive_more = "0.99.11"
20-
bounded-collections = { version = "0.1.7", default-features = false }
20+
bounded-collections = { version = "0.1.7", default-features = false, features = ["serde"] }
2121

2222
# all optional crates.
23-
serde = { version = "1.0.163", default-features = false, features = [ "derive" ], optional = true }
23+
serde = { version = "1.0.163", default-features = false, features = ["derive", "alloc"] }
2424

2525
[features]
2626
default = ["std"]

parachain/src/primitives.rs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@ use bounded_collections::{BoundedVec, ConstU32};
2323
use frame_support::weights::Weight;
2424
use parity_scale_codec::{CompactAs, Decode, Encode, MaxEncodedLen};
2525
use scale_info::TypeInfo;
26-
use sp_core::{RuntimeDebug, TypeId};
27-
use sp_runtime::traits::Hash as _;
28-
29-
#[cfg(feature = "std")]
3026
use serde::{Deserialize, Serialize};
31-
32-
#[cfg(feature = "std")]
33-
use sp_core::bytes;
27+
use sp_core::{bytes, RuntimeDebug, TypeId};
28+
use sp_runtime::traits::Hash as _;
3429

3530
use polkadot_core_primitives::{Hash, OutboundHrmpMessage};
3631

@@ -39,10 +34,21 @@ pub use polkadot_core_primitives::BlockNumber as RelayChainBlockNumber;
3934

4035
/// Parachain head data included in the chain.
4136
#[derive(
42-
PartialEq, Eq, Clone, PartialOrd, Ord, Encode, Decode, RuntimeDebug, derive_more::From, TypeInfo,
37+
PartialEq,
38+
Eq,
39+
Clone,
40+
PartialOrd,
41+
Ord,
42+
Encode,
43+
Decode,
44+
RuntimeDebug,
45+
derive_more::From,
46+
TypeInfo,
47+
Serialize,
48+
Deserialize,
4349
)]
44-
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash, Default))]
45-
pub struct HeadData(#[cfg_attr(feature = "std", serde(with = "bytes"))] pub Vec<u8>);
50+
#[cfg_attr(feature = "std", derive(Hash, Default))]
51+
pub struct HeadData(#[serde(with = "bytes")] pub Vec<u8>);
4652

4753
impl HeadData {
4854
/// Returns the hash of this head data.
@@ -52,9 +58,20 @@ impl HeadData {
5258
}
5359

5460
/// Parachain validation code.
55-
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, derive_more::From, TypeInfo)]
56-
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash))]
57-
pub struct ValidationCode(#[cfg_attr(feature = "std", serde(with = "bytes"))] pub Vec<u8>);
61+
#[derive(
62+
PartialEq,
63+
Eq,
64+
Clone,
65+
Encode,
66+
Decode,
67+
RuntimeDebug,
68+
derive_more::From,
69+
TypeInfo,
70+
Serialize,
71+
Deserialize,
72+
)]
73+
#[cfg_attr(feature = "std", derive(Hash))]
74+
pub struct ValidationCode(#[serde(with = "bytes")] pub Vec<u8>);
5875

5976
impl ValidationCode {
6077
/// Get the blake2-256 hash of the validation code bytes.
@@ -129,9 +146,11 @@ pub struct BlockData(#[cfg_attr(feature = "std", serde(with = "bytes"))] pub Vec
129146
PartialEq,
130147
PartialOrd,
131148
RuntimeDebug,
149+
serde::Serialize,
150+
serde::Deserialize,
132151
TypeInfo,
133152
)]
134-
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize, derive_more::Display))]
153+
#[cfg_attr(feature = "std", derive(derive_more::Display))]
135154
pub struct Id(u32);
136155

137156
impl TypeId for Id {

primitives/Cargo.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ edition.workspace = true
88
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
99
hex-literal = "0.4.1"
1010
parity-scale-codec = { version = "3.4.0", default-features = false, features = ["bit-vec", "derive"] }
11-
scale-info = { version = "2.5.0", default-features = false, features = ["bit-vec", "derive"] }
12-
serde = { version = "1.0.163", optional = true, features = ["derive"] }
11+
scale-info = { version = "2.5.0", default-features = false, features = ["bit-vec", "derive", "serde"] }
12+
serde = { version = "1.0.163", default-features = false, features = ["derive", "alloc"] }
1313

14-
application-crypto = { package = "sp-application-crypto", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
14+
application-crypto = { package = "sp-application-crypto", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, features = ["serde"] }
1515
inherents = { package = "sp-inherents", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
1616
primitives = { package = "sp-core", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
1717
runtime_primitives = { package = "sp-runtime", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
1818
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
19-
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
20-
sp-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
21-
sp-consensus-slots = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
19+
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, features = ["serde"] }
20+
sp-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, features = ["serde"] }
21+
sp-consensus-slots = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, features = ["serde"] }
2222
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
23-
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
24-
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
23+
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true , features = ["serde"]}
24+
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, features = ["serde"] }
2525
sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
2626

2727
polkadot-core-primitives = { path = "../core-primitives", default-features = false }
@@ -44,7 +44,7 @@ std = [
4444
"sp-staking/std",
4545
"sp-arithmetic/std",
4646
"runtime_primitives/std",
47-
"serde",
47+
"serde/std",
4848
"polkadot-parachain/std",
4949
"polkadot-core-primitives/std",
5050
"bitvec/std",

primitives/src/v4/executor_params.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ use crate::{BlakeTwo256, HashT as _, PvfExecTimeoutKind, PvfPrepTimeoutKind};
2525
use parity_scale_codec::{Decode, Encode};
2626
use polkadot_core_primitives::Hash;
2727
use scale_info::TypeInfo;
28+
use serde::{Deserialize, Serialize};
2829
use sp_std::{ops::Deref, time::Duration, vec, vec::Vec};
2930

3031
/// The different executor parameters for changing the execution environment semantics.
31-
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo)]
32-
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
32+
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo, Serialize, Deserialize)]
3333
pub enum ExecutorParam {
3434
/// Maximum number of memory pages (64KiB bytes per page) the executor can allocate.
3535
#[codec(index = 1)]
@@ -93,8 +93,7 @@ impl sp_std::fmt::LowerHex for ExecutorParamsHash {
9393
// into individual fields of the structure. Thus, complex migrations shall be avoided when adding
9494
// new entries and removing old ones. At the moment, there's no mandatory parameters defined. If
9595
// they show up, they must be clearly documented as mandatory ones.
96-
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo)]
97-
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
96+
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo, Serialize, Deserialize)]
9897
pub struct ExecutorParams(Vec<ExecutorParam>);
9998

10099
impl ExecutorParams {

primitives/src/v4/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ pub use polkadot_parachain::primitives::{
4747
ValidationCodeHash, LOWEST_PUBLIC_ID, LOWEST_USER_ID,
4848
};
4949

50-
#[cfg(feature = "std")]
5150
use serde::{Deserialize, Serialize};
5251

5352
pub use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
@@ -1762,8 +1761,7 @@ impl<T: Encode> WellKnownKey<T> {
17621761
}
17631762

17641763
/// Type discriminator for PVF preparation timeouts
1765-
#[derive(Encode, Decode, TypeInfo, Clone, Copy, Debug, PartialEq, Eq)]
1766-
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
1764+
#[derive(Encode, Decode, TypeInfo, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
17671765
pub enum PvfPrepTimeoutKind {
17681766
/// For prechecking requests, the time period after which the preparation worker is considered
17691767
/// unresponsive and will be killed.
@@ -1776,8 +1774,7 @@ pub enum PvfPrepTimeoutKind {
17761774
}
17771775

17781776
/// Type discriminator for PVF execution timeouts
1779-
#[derive(Encode, Decode, TypeInfo, Clone, Copy, Debug, PartialEq, Eq)]
1780-
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
1777+
#[derive(Encode, Decode, TypeInfo, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
17811778
pub enum PvfExecTimeoutKind {
17821779
/// The amount of time to spend on execution during backing.
17831780
Backing,

primitives/src/vstaging/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,17 @@ use primitives::RuntimeDebug;
2626
use scale_info::TypeInfo;
2727

2828
/// Candidate's acceptance limitations for asynchronous backing per relay parent.
29-
#[derive(RuntimeDebug, Copy, Clone, PartialEq, Encode, Decode, TypeInfo)]
30-
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
29+
#[derive(
30+
RuntimeDebug,
31+
Copy,
32+
Clone,
33+
PartialEq,
34+
Encode,
35+
Decode,
36+
TypeInfo,
37+
serde::Serialize,
38+
serde::Deserialize,
39+
)]
3140
pub struct AsyncBackingParams {
3241
/// The maximum number of para blocks between the para head in a relay parent
3342
/// and a new candidate. Restricts nodes from building arbitrary long chains

runtime/common/Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ parity-scale-codec = { version = "3.4.0", default-features = false, features = [
1111
log = { version = "0.4.17", default-features = false }
1212
rustc-hex = { version = "2.1.0", default-features = false }
1313
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
14-
serde = { version = "1.0.163", default-features = false }
15-
serde_derive = { version = "1.0.117", optional = true }
14+
serde = { version = "1.0.163", default-features = false, features = ["alloc"] }
15+
serde_derive = { version = "1.0.117" }
1616
static_assertions = "1.1.0"
1717

1818
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
1919
inherents = { package = "sp-inherents", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
2020
sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
2121
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
22-
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
22+
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false , features=["serde"]}
2323
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
24-
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
25-
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
26-
sp-npos-elections = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
24+
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, features=["serde"] }
25+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false , features=["serde"]}
26+
sp-npos-elections = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, features=["serde"] }
2727

2828
pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
2929
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
@@ -70,7 +70,6 @@ std = [
7070
"scale-info/std",
7171
"log/std",
7272
"rustc-hex/std",
73-
"serde_derive",
7473
"serde/std",
7574
"primitives/std",
7675
"inherents/std",

runtime/common/src/claims.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub use pallet::*;
2626
use parity_scale_codec::{Decode, Encode};
2727
use primitives::ValidityError;
2828
use scale_info::TypeInfo;
29-
#[cfg(feature = "std")]
3029
use serde::{self, Deserialize, Deserializer, Serialize, Serializer};
3130
use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256};
3231
use sp_runtime::{
@@ -36,6 +35,8 @@ use sp_runtime::{
3635
},
3736
RuntimeDebug,
3837
};
38+
#[cfg(not(feature = "std"))]
39+
use sp_std::alloc::{format, string::String};
3940
use sp_std::{fmt::Debug, prelude::*};
4041

4142
type CurrencyOf<T> = <<T as Config>::VestingSchedule as VestingSchedule<
@@ -71,8 +72,9 @@ impl WeightInfo for TestWeightInfo {
7172
}
7273

7374
/// The kind of statement an account needs to make for a claim to be valid.
74-
#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo)]
75-
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
75+
#[derive(
76+
Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo, Serialize, Deserialize,
77+
)]
7678
pub enum StatementKind {
7779
/// Statement required to be made by non-SAFT holders.
7880
Regular,
@@ -108,7 +110,6 @@ impl Default for StatementKind {
108110
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)]
109111
pub struct EthereumAddress([u8; 20]);
110112

111-
#[cfg(feature = "std")]
112113
impl Serialize for EthereumAddress {
113114
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
114115
where
@@ -119,7 +120,6 @@ impl Serialize for EthereumAddress {
119120
}
120121
}
121122

122-
#[cfg(feature = "std")]
123123
impl<'de> Deserialize<'de> for EthereumAddress {
124124
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
125125
where

runtime/parachains/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ parity-scale-codec = { version = "3.4.0", default-features = false, features = [
1010
log = { version = "0.4.17", default-features = false }
1111
rustc-hex = { version = "2.1.0", default-features = false }
1212
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
13-
serde = { version = "1.0.163", features = [ "derive" ], optional = true }
13+
serde = { version = "1.0.163", default-features = false, features = ["derive", "alloc"] }
1414
derive_more = "0.99.17"
1515
bitflags = "1.3.2"
1616

1717
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
1818
inherents = { package = "sp-inherents", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
1919
sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
2020
sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
21-
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
21+
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, features=["serde"] }
2222
sp-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
23-
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
24-
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
25-
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
23+
sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, features=["serde"] }
24+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, features=["serde"] }
25+
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true, features=["serde"] }
2626
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
2727
sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
2828

@@ -69,7 +69,7 @@ std = [
6969
"parity-scale-codec/std",
7070
"rustc-hex/std",
7171
"scale-info/std",
72-
"serde",
72+
"serde/std",
7373
"primitives/std",
7474
"inherents/std",
7575
"sp-core/std",

0 commit comments

Comments
 (0)