From 60423bc9db3f70774b0dc9968ca1a11b0cf4e3a9 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 2 Jul 2021 21:07:49 +0200 Subject: [PATCH 01/11] Update impl-codec to use new upstream MaxEncodedLen trait --- Cargo.lock | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 737a762d88f0d..74a12e9e9da99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2701,9 +2701,9 @@ dependencies = [ [[package]] name = "impl-codec" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df170efa359aebdd5cb7fe78edcc67107748e4737bdca8a8fb40d15ea7a877ed" +checksum = "161ebdfec3c8e3b52bf61c4f3550a1eea4f9579d10dc1b936f3171ebdcd6c443" dependencies = [ "parity-scale-codec", ] @@ -5759,24 +5759,25 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0f518afaa5a47d0d6386229b0a6e01e86427291d643aa4cabb4992219f504f8" +checksum = "8975095a2a03bbbdc70a74ab11a4f76a6d0b84680d87c68d722531b0ac28e8a9" dependencies = [ "arrayvec 0.7.0", "bitvec", "byte-slice-cast", + "impl-trait-for-tuples", "parity-scale-codec-derive", "serde", ] [[package]] name = "parity-scale-codec-derive" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f44c5f94427bd0b5076e8f7e15ca3f60a4d8ac0077e4793884e6fdfd8915344e" +checksum = "40dbbfef7f0a1143c5b06e0d76a6278e25dac0bc1af4be51a0fbb73f07e7ad09" dependencies = [ - "proc-macro-crate 0.1.5", + "proc-macro-crate 1.0.0", "proc-macro2", "quote", "syn", From 6a783184da39882c5a0c7183ded2d1a07fabc007 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 21 Jun 2021 14:44:49 +0200 Subject: [PATCH 02/11] Adapt crates to use the updated codec crate for `MaxEncodedLen` --- Cargo.lock | 8 -------- bin/node/runtime/Cargo.toml | 3 --- frame/assets/Cargo.toml | 2 -- frame/balances/Cargo.toml | 2 -- frame/proxy/Cargo.toml | 2 -- frame/support/Cargo.toml | 2 -- frame/support/src/lib.rs | 4 ---- frame/support/src/traits.rs | 2 +- primitives/application-crypto/Cargo.toml | 2 -- primitives/application-crypto/src/lib.rs | 6 ++---- primitives/core/Cargo.toml | 2 -- primitives/core/src/crypto.rs | 3 +-- primitives/core/src/ecdsa.rs | 4 ++-- primitives/core/src/ed25519.rs | 4 ++-- primitives/core/src/sr25519.rs | 4 ++-- primitives/runtime/Cargo.toml | 2 -- primitives/runtime/src/traits.rs | 3 +-- 17 files changed, 11 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74a12e9e9da99..90a2ee732b52e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1842,7 +1842,6 @@ dependencies = [ "frame-system", "impl-trait-for-tuples", "log", - "max-encoded-len", "once_cell", "parity-scale-codec", "parity-util-mem", @@ -4369,7 +4368,6 @@ dependencies = [ "frame-try-runtime", "hex-literal", "log", - "max-encoded-len", "node-primitives", "pallet-assets", "pallet-authority-discovery", @@ -4711,7 +4709,6 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "max-encoded-len", "pallet-balances", "parity-scale-codec", "sp-core", @@ -4822,7 +4819,6 @@ dependencies = [ "frame-support", "frame-system", "log", - "max-encoded-len", "pallet-transaction-payment", "parity-scale-codec", "sp-core", @@ -5349,7 +5345,6 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "max-encoded-len", "pallet-balances", "pallet-utility", "parity-scale-codec", @@ -8730,7 +8725,6 @@ dependencies = [ name = "sp-application-crypto" version = "3.0.0" dependencies = [ - "max-encoded-len", "parity-scale-codec", "serde", "sp-core", @@ -8942,7 +8936,6 @@ dependencies = [ "lazy_static", "libsecp256k1", "log", - "max-encoded-len", "merlin", "num-traits", "parity-scale-codec", @@ -9169,7 +9162,6 @@ dependencies = [ "hash256-std-hasher", "impl-trait-for-tuples", "log", - "max-encoded-len", "parity-scale-codec", "parity-util-mem", "paste 1.0.4", diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index 9b182c4085790..b1dc58107a6ce 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -90,8 +90,6 @@ pallet-transaction-storage = { version = "3.0.0", default-features = false, path pallet-uniques = { version = "3.0.0", default-features = false, path = "../../../frame/uniques" } pallet-vesting = { version = "3.0.0", default-features = false, path = "../../../frame/vesting" } -max-encoded-len = { version = "3.0.0", default-features = false, path = "../../../max-encoded-len", features = [ "derive" ] } - [build-dependencies] substrate-wasm-builder = { version = "4.0.0", path = "../../../utils/wasm-builder" } @@ -166,7 +164,6 @@ std = [ "log/std", "frame-try-runtime/std", "sp-npos-elections/std", - "max-encoded-len/std", ] runtime-benchmarks = [ "frame-benchmarking", diff --git a/frame/assets/Cargo.toml b/frame/assets/Cargo.toml index 7afd08d8c11f9..7137cf1d789a2 100644 --- a/frame/assets/Cargo.toml +++ b/frame/assets/Cargo.toml @@ -22,7 +22,6 @@ frame-support = { version = "3.0.0", default-features = false, path = "../suppor # `system` module provides us with all sorts of useful stuff and macros depend on it being around. frame-system = { version = "3.0.0", default-features = false, path = "../system" } frame-benchmarking = { version = "3.1.0", default-features = false, path = "../benchmarking", optional = true } -max-encoded-len = { version = "3.0.0", default-features = false, path = "../../max-encoded-len", features = [ "derive" ] } [dev-dependencies] sp-core = { version = "3.0.0", path = "../../primitives/core" } @@ -39,7 +38,6 @@ std = [ "frame-support/std", "frame-system/std", "frame-benchmarking/std", - "max-encoded-len/std", ] runtime-benchmarks = [ "frame-benchmarking", diff --git a/frame/balances/Cargo.toml b/frame/balances/Cargo.toml index c4ab509aa0d4e..116a52151583a 100644 --- a/frame/balances/Cargo.toml +++ b/frame/balances/Cargo.toml @@ -20,7 +20,6 @@ frame-benchmarking = { version = "3.1.0", default-features = false, path = "../b frame-support = { version = "3.0.0", default-features = false, path = "../support" } frame-system = { version = "3.0.0", default-features = false, path = "../system" } log = { version = "0.4.14", default-features = false } -max-encoded-len = { version = "3.0.0", default-features = false, path = "../../max-encoded-len", features = [ "derive" ] } [dev-dependencies] sp-io = { version = "3.0.0", path = "../../primitives/io" } @@ -37,7 +36,6 @@ std = [ "frame-support/std", "frame-system/std", "log/std", - "max-encoded-len/std", ] runtime-benchmarks = ["frame-benchmarking"] try-runtime = ["frame-support/try-runtime"] diff --git a/frame/proxy/Cargo.toml b/frame/proxy/Cargo.toml index deec8aab72682..a4b47dc2b09ba 100644 --- a/frame/proxy/Cargo.toml +++ b/frame/proxy/Cargo.toml @@ -20,7 +20,6 @@ sp-core = { version = "3.0.0", default-features = false, path = "../../primitive sp-io = { version = "3.0.0", default-features = false, path = "../../primitives/io" } sp-runtime = { version = "3.0.0", default-features = false, path = "../../primitives/runtime" } sp-std = { version = "3.0.0", default-features = false, path = "../../primitives/std" } -max-encoded-len = { version = "3.0.0", default-features = false, path = "../../max-encoded-len", features = [ "derive" ] } frame-benchmarking = { version = "3.1.0", default-features = false, path = "../benchmarking", optional = true } @@ -38,7 +37,6 @@ std = [ "frame-system/std", "sp-std/std", "sp-io/std", - "max-encoded-len/std", ] runtime-benchmarks = [ "frame-benchmarking", diff --git a/frame/support/Cargo.toml b/frame/support/Cargo.toml index 0c9aacaf307b1..173e3da27984d 100644 --- a/frame/support/Cargo.toml +++ b/frame/support/Cargo.toml @@ -16,7 +16,6 @@ targets = ["x86_64-unknown-linux-gnu"] serde = { version = "1.0.101", optional = true, features = ["derive"] } codec = { package = "parity-scale-codec", version = "2.1.0", default-features = false, features = ["derive"] } frame-metadata = { version = "13.0.0", default-features = false, path = "../metadata" } -max-encoded-len = { version = "3.0.0", default-features = false, path = "../../max-encoded-len", features = [ "derive" ] } sp-std = { version = "3.0.0", default-features = false, path = "../../primitives/std" } sp-io = { version = "3.0.0", default-features = false, path = "../../primitives/io" } sp-runtime = { version = "3.0.0", default-features = false, path = "../../primitives/runtime" } @@ -56,7 +55,6 @@ std = [ "sp-state-machine", "frame-support-procedural/std", "log/std", - "max-encoded-len/std", ] runtime-benchmarks = [] try-runtime = [] diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 638485360c589..cceb4bbd3bd8c 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -2374,7 +2374,3 @@ pub mod pallet_prelude { /// * use the newest nightly possible. /// pub use frame_support_procedural::pallet; - -/// The `max_encoded_len` module contains the `MaxEncodedLen` trait and derive macro, which is -/// useful for computing upper bounds on storage size. -pub use max_encoded_len; diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 96e1cece55065..f1a5bea7cad5d 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -83,4 +83,4 @@ mod voting; pub use voting::{CurrencyToVote, SaturatingCurrencyToVote, U128CurrencyToVote}; // for backwards-compatibility with existing imports -pub use max_encoded_len::MaxEncodedLen; +pub use codec::MaxEncodedLen; diff --git a/primitives/application-crypto/Cargo.toml b/primitives/application-crypto/Cargo.toml index 7f3e48ae48255..050d2468aa00d 100644 --- a/primitives/application-crypto/Cargo.toml +++ b/primitives/application-crypto/Cargo.toml @@ -20,7 +20,6 @@ codec = { package = "parity-scale-codec", version = "2.0.0", default-features = serde = { version = "1.0.101", optional = true, features = ["derive"] } sp-std = { version = "3.0.0", default-features = false, path = "../std" } sp-io = { version = "3.0.0", default-features = false, path = "../io" } -max-encoded-len = { version = "3.0.0", default-features = false, path = "../../max-encoded-len", features = [ "derive" ] } [features] default = [ "std" ] @@ -31,7 +30,6 @@ std = [ "serde", "sp-std/std", "sp-io/std", - "max-encoded-len/std", ] # This feature enables all crypto primitives for `no_std` builds like microcontrollers diff --git a/primitives/application-crypto/src/lib.rs b/primitives/application-crypto/src/lib.rs index 58e5c5b7a311f..ca175ddbed915 100644 --- a/primitives/application-crypto/src/lib.rs +++ b/primitives/application-crypto/src/lib.rs @@ -39,8 +39,6 @@ pub use sp_std::{ ops::Deref, vec::Vec, }; -#[doc(hidden)] -pub use max_encoded_len; pub mod ed25519; pub mod sr25519; @@ -200,9 +198,9 @@ macro_rules! app_crypto_public_full_crypto { $crate::codec::Encode, $crate::codec::Decode, $crate::RuntimeDebug, - $crate::max_encoded_len::MaxEncodedLen, + $crate::codec::MaxEncodedLen, )] - #[max_encoded_len_crate($crate::max_encoded_len)] + #[codec(crate = $crate::codec)] pub struct Public($public); } diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index 0c724d61ae0cc..a0bed58e8bb52 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -40,7 +40,6 @@ parity-util-mem = { version = "0.9.0", default-features = false, features = ["pr futures = { version = "0.3.1", optional = true } dyn-clonable = { version = "0.9.0", optional = true } thiserror = { version = "1.0.21", optional = true } -max-encoded-len = { version = "3.0.0", default-features = false, path = "../../max-encoded-len", features = [ "derive" ] } # full crypto ed25519-dalek = { version = "1.0.1", default-features = false, features = ["u64_backend", "alloc"], optional = true } @@ -114,7 +113,6 @@ std = [ "futures/thread-pool", "libsecp256k1/std", "dyn-clonable", - "max-encoded-len/std", ] # This feature enables all crypto primitives for `no_std` builds like microcontrollers diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index d9a0a69e16813..a4dc7f6baa46a 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -20,7 +20,6 @@ // end::description[] use crate::{sr25519, ed25519}; -use max_encoded_len::MaxEncodedLen; use sp_std::hash::Hash; use sp_std::vec::Vec; use sp_std::str; @@ -31,7 +30,7 @@ use sp_std::convert::TryFrom; use parking_lot::Mutex; #[cfg(feature = "std")] use rand::{RngCore, rngs::OsRng}; -use codec::{Encode, Decode}; +use codec::{Encode, Decode, MaxEncodedLen}; #[cfg(feature = "std")] use regex::Regex; #[cfg(feature = "std")] diff --git a/primitives/core/src/ecdsa.rs b/primitives/core/src/ecdsa.rs index c567b3c44f6ce..ffdb5f5c4c990 100644 --- a/primitives/core/src/ecdsa.rs +++ b/primitives/core/src/ecdsa.rs @@ -23,7 +23,7 @@ use sp_std::vec::Vec; use sp_std::cmp::Ordering; -use codec::{Encode, Decode}; +use codec::{Encode, Decode, MaxEncodedLen}; #[cfg(feature = "full_crypto")] use core::convert::{TryFrom, TryInto}; @@ -52,7 +52,7 @@ pub const CRYPTO_ID: CryptoTypeId = CryptoTypeId(*b"ecds"); type Seed = [u8; 32]; /// The ECDSA compressed public key. -#[derive(Clone, Encode, Decode, PassByInner, max_encoded_len::MaxEncodedLen)] +#[derive(Clone, Encode, Decode, PassByInner, MaxEncodedLen)] pub struct Public(pub [u8; 33]); impl PartialOrd for Public { diff --git a/primitives/core/src/ed25519.rs b/primitives/core/src/ed25519.rs index 392dc2eec6c66..13ee4d8cdfbcd 100644 --- a/primitives/core/src/ed25519.rs +++ b/primitives/core/src/ed25519.rs @@ -23,7 +23,7 @@ use sp_std::vec::Vec; use crate::{hash::H256, hash::H512}; -use codec::{Encode, Decode}; +use codec::{Encode, Decode, MaxEncodedLen}; #[cfg(feature = "full_crypto")] use core::convert::TryFrom; @@ -56,7 +56,7 @@ type Seed = [u8; 32]; #[cfg_attr(feature = "full_crypto", derive(Hash))] #[derive( PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Encode, Decode, Default, PassByInner, - max_encoded_len::MaxEncodedLen, + MaxEncodedLen, )] pub struct Public(pub [u8; 32]); diff --git a/primitives/core/src/sr25519.rs b/primitives/core/src/sr25519.rs index 269f19cba0073..dbfb8ba1d26fd 100644 --- a/primitives/core/src/sr25519.rs +++ b/primitives/core/src/sr25519.rs @@ -42,7 +42,7 @@ use crate::crypto::Ss58Codec; use crate::crypto::{Public as TraitPublic, CryptoTypePublicPair, UncheckedFrom, CryptoType, Derive, CryptoTypeId}; use crate::hash::{H256, H512}; -use codec::{Encode, Decode}; +use codec::{Encode, Decode, MaxEncodedLen}; use sp_std::ops::Deref; #[cfg(feature = "std")] @@ -62,7 +62,7 @@ pub const CRYPTO_ID: CryptoTypeId = CryptoTypeId(*b"sr25"); #[cfg_attr(feature = "full_crypto", derive(Hash))] #[derive( PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Encode, Decode, Default, PassByInner, - max_encoded_len::MaxEncodedLen, + MaxEncodedLen, )] pub struct Public(pub [u8; 32]); diff --git a/primitives/runtime/Cargo.toml b/primitives/runtime/Cargo.toml index aec2bc416ee37..7d33e7fa62d2d 100644 --- a/primitives/runtime/Cargo.toml +++ b/primitives/runtime/Cargo.toml @@ -29,7 +29,6 @@ impl-trait-for-tuples = "0.2.1" parity-util-mem = { version = "0.9.0", default-features = false, features = ["primitive-types"] } hash256-std-hasher = { version = "0.15.2", default-features = false } either = { version = "1.5", default-features = false } -max-encoded-len = { version = "3.0.0", default-features = false, path = "../../max-encoded-len", features = [ "derive" ] } [dev-dependencies] serde_json = "1.0.41" @@ -56,5 +55,4 @@ std = [ "parity-util-mem/std", "hash256-std-hasher/std", "either/use_std", - "max-encoded-len/std", ] diff --git a/primitives/runtime/src/traits.rs b/primitives/runtime/src/traits.rs index 2379fce9949e0..fac4adf48c266 100644 --- a/primitives/runtime/src/traits.rs +++ b/primitives/runtime/src/traits.rs @@ -26,7 +26,7 @@ use std::str::FromStr; #[cfg(feature = "std")] use serde::{Serialize, Deserialize, de::DeserializeOwned}; use sp_core::{self, Hasher, TypeId, RuntimeDebug}; -use crate::codec::{Codec, Encode, Decode}; +use crate::codec::{Codec, Encode, Decode, MaxEncodedLen}; use crate::transaction_validity::{ ValidTransaction, TransactionSource, TransactionValidity, TransactionValidityError, UnknownTransaction, @@ -40,7 +40,6 @@ pub use sp_arithmetic::traits::{ use sp_application_crypto::AppKey; use impl_trait_for_tuples::impl_for_tuples; use crate::DispatchResult; -use max_encoded_len::MaxEncodedLen; /// A lazy value. pub trait Lazy { From b8e619634b83e42e1588e8b66fcf99887fc6c76d Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 21 Jun 2021 14:59:59 +0200 Subject: [PATCH 03/11] Remove max-encoded-len crate altogether --- Cargo.lock | 23 -- Cargo.toml | 3 - max-encoded-len/Cargo.toml | 36 ---- max-encoded-len/derive/Cargo.toml | 25 --- max-encoded-len/derive/src/lib.rs | 204 ------------------ max-encoded-len/src/lib.rs | 161 -------------- max-encoded-len/tests/max_encoded_len.rs | 151 ------------- max-encoded-len/tests/max_encoded_len_ui.rs | 27 --- .../max_encoded_len_ui/list_list_item.rs | 10 - .../max_encoded_len_ui/list_list_item.stderr | 18 -- .../max_encoded_len_ui/literal_list_item.rs | 10 - .../literal_list_item.stderr | 18 -- .../max_encoded_len_ui/name_value_attr.rs | 10 - .../max_encoded_len_ui/name_value_attr.stderr | 18 -- .../name_value_list_item.rs | 10 - .../name_value_list_item.stderr | 18 -- .../max_encoded_len_ui/no_path_list_items.rs | 10 - .../no_path_list_items.stderr | 18 -- .../tests/max_encoded_len_ui/not_encode.rs | 6 - .../max_encoded_len_ui/not_encode.stderr | 13 -- .../tests/max_encoded_len_ui/not_mel.rs | 14 -- .../tests/max_encoded_len_ui/not_mel.stderr | 21 -- .../tests/max_encoded_len_ui/path_attr.rs | 10 - .../tests/max_encoded_len_ui/path_attr.stderr | 18 -- .../max_encoded_len_ui/two_path_list_items.rs | 10 - .../two_path_list_items.stderr | 18 -- .../tests/max_encoded_len_ui/union.rs | 10 - .../tests/max_encoded_len_ui/union.stderr | 11 - .../max_encoded_len_ui/unsupported_variant.rs | 12 -- .../unsupported_variant.stderr | 12 -- 30 files changed, 925 deletions(-) delete mode 100644 max-encoded-len/Cargo.toml delete mode 100644 max-encoded-len/derive/Cargo.toml delete mode 100644 max-encoded-len/derive/src/lib.rs delete mode 100644 max-encoded-len/src/lib.rs delete mode 100644 max-encoded-len/tests/max_encoded_len.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/list_list_item.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/list_list_item.stderr delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/literal_list_item.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/literal_list_item.stderr delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/name_value_attr.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/name_value_attr.stderr delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/name_value_list_item.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/name_value_list_item.stderr delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/no_path_list_items.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/no_path_list_items.stderr delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/not_encode.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/not_encode.stderr delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/not_mel.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/not_mel.stderr delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/path_attr.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/path_attr.stderr delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/two_path_list_items.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/two_path_list_items.stderr delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/union.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/union.stderr delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/unsupported_variant.rs delete mode 100644 max-encoded-len/tests/max_encoded_len_ui/unsupported_variant.stderr diff --git a/Cargo.lock b/Cargo.lock index 90a2ee732b52e..0f7b7395427db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3772,29 +3772,6 @@ dependencies = [ "rawpointer", ] -[[package]] -name = "max-encoded-len" -version = "3.0.0" -dependencies = [ - "frame-support", - "impl-trait-for-tuples", - "max-encoded-len-derive", - "parity-scale-codec", - "primitive-types", - "rustversion", - "trybuild", -] - -[[package]] -name = "max-encoded-len-derive" -version = "3.0.0" -dependencies = [ - "proc-macro-crate 1.0.0", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "maybe-uninit" version = "2.0.0" diff --git a/Cargo.toml b/Cargo.toml index d73bf1b52de90..599130c52ae34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -204,9 +204,6 @@ members = [ "utils/frame/rpc/system", "utils/prometheus", "utils/wasm-builder", - # temp deps - "max-encoded-len", - "max-encoded-len/derive", ] # The list of dependencies below (which can be both direct and indirect dependencies) are crates diff --git a/max-encoded-len/Cargo.toml b/max-encoded-len/Cargo.toml deleted file mode 100644 index 994a3c6a5e132..0000000000000 --- a/max-encoded-len/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "max-encoded-len" -version = "3.0.0" -authors = ["Parity Technologies "] -edition = "2018" -license = "Apache-2.0" -homepage = "https://substrate.dev" -repository = "https://github.com/paritytech/substrate/" -description = "Trait MaxEncodedLen bounds the max encoded length of an item." - - -[dependencies] -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false } -impl-trait-for-tuples = "0.2.1" -max-encoded-len-derive = { package = "max-encoded-len-derive", version = "3.0.0", path = "derive", default-features = false, optional = true } -primitive-types = { version = "0.9.0", default-features = false, features = ["codec"] } - -[dev-dependencies] -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [ "derive" ] } -frame-support = { path = "../frame/support" } -rustversion = "1.0.4" -trybuild = "1.0.42" - -[features] -default = [ - "derive", - "std", -] -derive = [ - "max-encoded-len-derive", -] -std = [ - "codec/std", - "max-encoded-len-derive/std", - "primitive-types/std", -] diff --git a/max-encoded-len/derive/Cargo.toml b/max-encoded-len/derive/Cargo.toml deleted file mode 100644 index 42c13dc50edd6..0000000000000 --- a/max-encoded-len/derive/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "max-encoded-len-derive" -version = "3.0.0" -authors = ["Parity Technologies "] -edition = "2018" -license = "Apache-2.0" -homepage = "https://substrate.dev" -repository = "https://github.com/paritytech/substrate/" -description = "Derive support for MaxEncodedLen" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[lib] -proc-macro = true - -[dependencies] -proc-macro2 = "1.0.6" -proc-macro-crate = "1.0.0" -quote = "1.0.3" -syn = { version = "1.0.58", features = ["full"] } - -[features] -default = ["std"] -std = [] diff --git a/max-encoded-len/derive/src/lib.rs b/max-encoded-len/derive/src/lib.rs deleted file mode 100644 index 34bf42f30cb33..0000000000000 --- a/max-encoded-len/derive/src/lib.rs +++ /dev/null @@ -1,204 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2021 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. - -use quote::{quote, quote_spanned}; -use syn::{ - Data, DeriveInput, Error, Fields, GenericParam, Generics, Meta, TraitBound, Type, - TypeParamBound, parse_quote, spanned::Spanned, -}; -use proc_macro_crate::{crate_name, FoundCrate}; -use proc_macro2::{Ident, Span}; - -/// Generate the crate access for the crate using 2018 syntax. -fn generate_crate_access_2018(def_crate: &str) -> Result { - match crate_name(def_crate) { - Ok(FoundCrate::Itself) => { - let name = def_crate.to_string().replace("-", "_"); - Ok(syn::Ident::new(&name, Span::call_site())) - }, - Ok(FoundCrate::Name(name)) => { - Ok(Ident::new(&name, Span::call_site())) - }, - Err(e) => { - Err(Error::new(Span::call_site(), e)) - } - } -} - -/// Derive `MaxEncodedLen`. -#[proc_macro_derive(MaxEncodedLen, attributes(max_encoded_len_crate))] -pub fn derive_max_encoded_len(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input: DeriveInput = match syn::parse(input) { - Ok(input) => input, - Err(e) => return e.to_compile_error().into(), - }; - - let mel_trait = match max_encoded_len_trait(&input) { - Ok(mel_trait) => mel_trait, - Err(e) => return e.to_compile_error().into(), - }; - - let name = &input.ident; - let generics = add_trait_bounds(input.generics, mel_trait.clone()); - let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); - - let data_expr = data_length_expr(&input.data); - - quote::quote!( - const _: () = { - impl #impl_generics #mel_trait for #name #ty_generics #where_clause { - fn max_encoded_len() -> usize { - #data_expr - } - } - }; - ) - .into() -} - -fn max_encoded_len_trait(input: &DeriveInput) -> syn::Result { - let mel = { - const EXPECT_LIST: &str = "expect: #[max_encoded_len_crate(path::to::crate)]"; - const EXPECT_PATH: &str = "expect: path::to::crate"; - - macro_rules! return_err { - ($wrong_style:expr, $err:expr) => { - return Err(Error::new($wrong_style.span(), $err)) - }; - } - - let mut mel_crates = Vec::with_capacity(2); - mel_crates.extend(input - .attrs - .iter() - .filter(|attr| attr.path == parse_quote!(max_encoded_len_crate)) - .take(2) - .map(|attr| { - let meta_list = match attr.parse_meta()? { - Meta::List(meta_list) => meta_list, - Meta::Path(wrong_style) => return_err!(wrong_style, EXPECT_LIST), - Meta::NameValue(wrong_style) => return_err!(wrong_style, EXPECT_LIST), - }; - if meta_list.nested.len() != 1 { - return_err!(meta_list, "expected exactly 1 item"); - } - let first_nested = - meta_list.nested.into_iter().next().expect("length checked above"); - let meta = match first_nested { - syn::NestedMeta::Lit(l) => { - return_err!(l, "expected a path item, not a literal") - } - syn::NestedMeta::Meta(meta) => meta, - }; - let path = match meta { - Meta::Path(path) => path, - Meta::List(ref wrong_style) => return_err!(wrong_style, EXPECT_PATH), - Meta::NameValue(ref wrong_style) => return_err!(wrong_style, EXPECT_PATH), - }; - Ok(path) - }) - .collect::, _>>()?); - - // we have to return `Result` here in order to satisfy the trait - // bounds for `.or_else` for `generate_crate_access_2018`, even though `Option` - // would be more natural in this circumstance. - match mel_crates.len() { - 0 => Err(Error::new( - input.span(), - "this error is spurious and swallowed by the or_else below", - )), - 1 => Ok(mel_crates.into_iter().next().expect("length is checked")), - _ => return_err!(mel_crates[1], "duplicate max_encoded_len_crate definition"), - } - } - .or_else(|_| generate_crate_access_2018("max-encoded-len").map(|ident| ident.into()))?; - Ok(parse_quote!(#mel::MaxEncodedLen)) -} - -// Add a bound `T: MaxEncodedLen` to every type parameter T. -fn add_trait_bounds(mut generics: Generics, mel_trait: TraitBound) -> Generics { - for param in &mut generics.params { - if let GenericParam::Type(ref mut type_param) = *param { - type_param.bounds.push(TypeParamBound::Trait(mel_trait.clone())); - } - } - generics -} - -/// generate an expression to sum up the max encoded length from several fields -fn fields_length_expr(fields: &Fields) -> proc_macro2::TokenStream { - let type_iter: Box> = match fields { - Fields::Named(ref fields) => Box::new(fields.named.iter().map(|field| &field.ty)), - Fields::Unnamed(ref fields) => Box::new(fields.unnamed.iter().map(|field| &field.ty)), - Fields::Unit => Box::new(std::iter::empty()), - }; - // expands to an expression like - // - // 0 - // .saturating_add(::max_encoded_len()) - // .saturating_add(::max_encoded_len()) - // - // We match the span of each field to the span of the corresponding - // `max_encoded_len` call. This way, if one field's type doesn't implement - // `MaxEncodedLen`, the compiler's error message will underline which field - // caused the issue. - let expansion = type_iter.map(|ty| { - quote_spanned! { - ty.span() => .saturating_add(<#ty>::max_encoded_len()) - } - }); - quote! { - 0_usize #( #expansion )* - } -} - -// generate an expression to sum up the max encoded length of each field -fn data_length_expr(data: &Data) -> proc_macro2::TokenStream { - match *data { - Data::Struct(ref data) => fields_length_expr(&data.fields), - Data::Enum(ref data) => { - // We need an expression expanded for each variant like - // - // 0 - // .max() - // .max() - // .saturating_add(1) - // - // The 1 derives from the discriminant; see - // https://github.com/paritytech/parity-scale-codec/ - // blob/f0341dabb01aa9ff0548558abb6dcc5c31c669a1/derive/src/encode.rs#L211-L216 - // - // Each variant expression's sum is computed the way an equivalent struct's would be. - - let expansion = data.variants.iter().map(|variant| { - let variant_expression = fields_length_expr(&variant.fields); - quote! { - .max(#variant_expression) - } - }); - - quote! { - 0_usize #( #expansion )* .saturating_add(1) - } - } - Data::Union(ref data) => { - // https://github.com/paritytech/parity-scale-codec/ - // blob/f0341dabb01aa9ff0548558abb6dcc5c31c669a1/derive/src/encode.rs#L290-L293 - Error::new(data.union_token.span(), "Union types are not supported").to_compile_error() - } - } -} diff --git a/max-encoded-len/src/lib.rs b/max-encoded-len/src/lib.rs deleted file mode 100644 index e216d3b174159..0000000000000 --- a/max-encoded-len/src/lib.rs +++ /dev/null @@ -1,161 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2021 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. - -//! `trait MaxEncodedLen` bounds the max encoded length of items. - -#![cfg_attr(not(feature = "std"), no_std)] - -use codec::{Compact, Encode}; -use impl_trait_for_tuples::impl_for_tuples; -use core::{mem, marker::PhantomData}; -use primitive_types::{H160, H256, H512}; - -/// Derive macro for `MaxEncodedLen`. -/// -/// ``` -/// # use max_encoded_len::MaxEncodedLen; -/// # use codec::Encode; -/// #[derive(Encode, MaxEncodedLen)] -/// struct Example; -/// ``` -/// -/// Sometimes the `MaxEncodedLen` trait and macro are accessed without explicitly importing its -/// crate, notably via the `frame_support::max_encoded_len` re-binding. In these circumstances, -/// the derive macro needs some help to understand where its crate should be: -/// -/// ``` -/// # use codec::Encode; -/// use frame_support::max_encoded_len::MaxEncodedLen; -/// -/// #[derive(Encode, MaxEncodedLen)] -/// #[max_encoded_len_crate(frame_support::max_encoded_len)] -/// struct Example; -/// ``` -#[cfg(feature = "derive")] -pub use max_encoded_len_derive::MaxEncodedLen; - -/// Items implementing `MaxEncodedLen` have a statically known maximum encoded size. -/// -/// Some containers, such as `BoundedVec`, have enforced size limits and this trait -/// can be implemented accurately. Other containers, such as `StorageMap`, do not have enforced size -/// limits. For those containers, it is necessary to make a documented assumption about the maximum -/// usage, and compute the max encoded length based on that assumption. -pub trait MaxEncodedLen: Encode { - /// Upper bound, in bytes, of the maximum encoded size of this item. - fn max_encoded_len() -> usize; -} - -macro_rules! impl_primitives { - ( $($t:ty),+ ) => { - $( - impl MaxEncodedLen for $t { - fn max_encoded_len() -> usize { - mem::size_of::<$t>() - } - } - )+ - }; -} - -impl_primitives!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, bool, H160, H256, H512); - -macro_rules! impl_compact { - ($( $t:ty => $e:expr; )*) => { - $( - impl MaxEncodedLen for Compact<$t> { - fn max_encoded_len() -> usize { - $e - } - } - )* - }; -} - -impl_compact!( - // github.com/paritytech/parity-scale-codec/blob/f0341dabb01aa9ff0548558abb6dcc5c31c669a1/src/compact.rs#L261 - u8 => 2; - // github.com/paritytech/parity-scale-codec/blob/f0341dabb01aa9ff0548558abb6dcc5c31c669a1/src/compact.rs#L291 - u16 => 4; - // github.com/paritytech/parity-scale-codec/blob/f0341dabb01aa9ff0548558abb6dcc5c31c669a1/src/compact.rs#L326 - u32 => 5; - // github.com/paritytech/parity-scale-codec/blob/f0341dabb01aa9ff0548558abb6dcc5c31c669a1/src/compact.rs#L369 - u64 => 9; - // github.com/paritytech/parity-scale-codec/blob/f0341dabb01aa9ff0548558abb6dcc5c31c669a1/src/compact.rs#L413 - u128 => 17; -); - -// impl_for_tuples for values 19 and higher fails because that's where the WrapperTypeEncode impl stops. -#[impl_for_tuples(18)] -impl MaxEncodedLen for Tuple { - fn max_encoded_len() -> usize { - let mut len: usize = 0; - for_tuples!( #( len = len.saturating_add(Tuple::max_encoded_len()); )* ); - len - } -} - -impl MaxEncodedLen for [T; N] { - fn max_encoded_len() -> usize { - T::max_encoded_len().saturating_mul(N) - } -} - -impl MaxEncodedLen for Option { - fn max_encoded_len() -> usize { - T::max_encoded_len().saturating_add(1) - } -} - -impl MaxEncodedLen for Result -where - T: MaxEncodedLen, - E: MaxEncodedLen, -{ - fn max_encoded_len() -> usize { - T::max_encoded_len().max(E::max_encoded_len()).saturating_add(1) - } -} - -impl MaxEncodedLen for PhantomData { - fn max_encoded_len() -> usize { - 0 - } -} - -#[cfg(test)] -mod tests { - use super::*; - - macro_rules! test_compact_length { - ($(fn $name:ident($t:ty);)*) => { - $( - #[test] - fn $name() { - assert_eq!(Compact(<$t>::MAX).encode().len(), Compact::<$t>::max_encoded_len()); - } - )* - }; - } - - test_compact_length!( - fn compact_u8(u8); - fn compact_u16(u16); - fn compact_u32(u32); - fn compact_u64(u64); - fn compact_u128(u128); - ); -} diff --git a/max-encoded-len/tests/max_encoded_len.rs b/max-encoded-len/tests/max_encoded_len.rs deleted file mode 100644 index 665ac8fa98a4f..0000000000000 --- a/max-encoded-len/tests/max_encoded_len.rs +++ /dev/null @@ -1,151 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2020-2021 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. - -//! Tests for MaxEncodedLen derive macro - -#![cfg(feature = "derive")] - -use max_encoded_len::MaxEncodedLen; -use codec::{Compact, Encode}; - -// These structs won't even compile if the macro isn't working right. - -#[derive(Encode, MaxEncodedLen)] -struct Primitives { - bool: bool, - eight: u8, -} - -#[test] -fn primitives_max_length() { - assert_eq!(Primitives::max_encoded_len(), 2); -} - -#[derive(Encode, MaxEncodedLen)] -struct Composites { - fixed_size_array: [u8; 128], - tuple: (u128, u128), -} - -#[test] -fn composites_max_length() { - assert_eq!(Composites::max_encoded_len(), 128 + 16 + 16); -} - -#[derive(Encode, MaxEncodedLen)] -struct Generic { - one: T, - two: T, -} - -#[test] -fn generic_max_length() { - assert_eq!(Generic::::max_encoded_len(), u8::max_encoded_len() * 2); - assert_eq!(Generic::::max_encoded_len(), u32::max_encoded_len() * 2); -} - -#[derive(Encode, MaxEncodedLen)] -struct TwoGenerics { - t: T, - u: U, -} - -#[test] -fn two_generics_max_length() { - assert_eq!( - TwoGenerics::::max_encoded_len(), - u8::max_encoded_len() + u16::max_encoded_len() - ); - assert_eq!( - TwoGenerics::, [u16; 8]>::max_encoded_len(), - Compact::::max_encoded_len() + <[u16; 8]>::max_encoded_len() - ); -} - -#[derive(Encode, MaxEncodedLen)] -struct UnitStruct; - -#[test] -fn unit_struct_max_length() { - assert_eq!(UnitStruct::max_encoded_len(), 0); -} - -#[derive(Encode, MaxEncodedLen)] -struct TupleStruct(u8, u32); - -#[test] -fn tuple_struct_max_length() { - assert_eq!(TupleStruct::max_encoded_len(), u8::max_encoded_len() + u32::max_encoded_len()); -} - -#[derive(Encode, MaxEncodedLen)] -struct TupleGeneric(T, T); - -#[test] -fn tuple_generic_max_length() { - assert_eq!(TupleGeneric::::max_encoded_len(), u8::max_encoded_len() * 2); - assert_eq!(TupleGeneric::::max_encoded_len(), u32::max_encoded_len() * 2); -} - -#[derive(Encode, MaxEncodedLen)] -#[allow(unused)] -enum UnitEnum { - A, - B, -} - -#[test] -fn unit_enum_max_length() { - assert_eq!(UnitEnum::max_encoded_len(), 1); -} - -#[derive(Encode, MaxEncodedLen)] -#[allow(unused)] -enum TupleEnum { - A(u32), - B, -} - -#[test] -fn tuple_enum_max_length() { - assert_eq!(TupleEnum::max_encoded_len(), 1 + u32::max_encoded_len()); -} - -#[derive(Encode, MaxEncodedLen)] -#[allow(unused)] -enum StructEnum { - A { sixty_four: u64, one_twenty_eight: u128 }, - B, -} - -#[test] -fn struct_enum_max_length() { - assert_eq!(StructEnum::max_encoded_len(), 1 + u64::max_encoded_len() + u128::max_encoded_len()); -} - -// ensure that enums take the max of variant length, not the sum -#[derive(Encode, MaxEncodedLen)] -#[allow(unused)] -enum EnumMaxNotSum { - A(u32), - B(u32), -} - -#[test] -fn enum_max_not_sum_max_length() { - assert_eq!(EnumMaxNotSum::max_encoded_len(), 1 + u32::max_encoded_len()); -} diff --git a/max-encoded-len/tests/max_encoded_len_ui.rs b/max-encoded-len/tests/max_encoded_len_ui.rs deleted file mode 100644 index 79d6d49234ff2..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui.rs +++ /dev/null @@ -1,27 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) 2020-2021 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. - -#[cfg(feature = "derive")] -#[rustversion::attr(not(stable), ignore)] -#[test] -fn derive_no_bound_ui() { - // As trybuild is using `cargo check`, we don't need the real WASM binaries. - std::env::set_var("SKIP_WASM_BUILD", "1"); - - let t = trybuild::TestCases::new(); - t.compile_fail("tests/max_encoded_len_ui/*.rs"); -} diff --git a/max-encoded-len/tests/max_encoded_len_ui/list_list_item.rs b/max-encoded-len/tests/max_encoded_len_ui/list_list_item.rs deleted file mode 100644 index 0cb12991fab45..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/list_list_item.rs +++ /dev/null @@ -1,10 +0,0 @@ -use codec::Encode; -use frame_support::max_encoded_len::MaxEncodedLen; - -#[derive(Encode, MaxEncodedLen)] -#[max_encoded_len_crate(foo())] -struct Example; - -fn main() { - let _ = Example::max_encoded_len(); -} diff --git a/max-encoded-len/tests/max_encoded_len_ui/list_list_item.stderr b/max-encoded-len/tests/max_encoded_len_ui/list_list_item.stderr deleted file mode 100644 index 4ecd40440a461..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/list_list_item.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: expect: path::to::crate - --> $DIR/list_list_item.rs:5:25 - | -5 | #[max_encoded_len_crate(foo())] - | ^^^ - -error[E0599]: no function or associated item named `max_encoded_len` found for struct `Example` in the current scope - --> $DIR/list_list_item.rs:9:19 - | -6 | struct Example; - | --------------- function or associated item `max_encoded_len` not found for this -... -9 | let _ = Example::max_encoded_len(); - | ^^^^^^^^^^^^^^^ function or associated item not found in `Example` - | - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following trait defines an item `max_encoded_len`, perhaps you need to implement it: - candidate #1: `MaxEncodedLen` diff --git a/max-encoded-len/tests/max_encoded_len_ui/literal_list_item.rs b/max-encoded-len/tests/max_encoded_len_ui/literal_list_item.rs deleted file mode 100644 index f3f7a72d813b6..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/literal_list_item.rs +++ /dev/null @@ -1,10 +0,0 @@ -use codec::Encode; -use frame_support::max_encoded_len::MaxEncodedLen; - -#[derive(Encode, MaxEncodedLen)] -#[max_encoded_len_crate("frame_support::max_encoded_len")] -struct Example; - -fn main() { - let _ = Example::max_encoded_len(); -} diff --git a/max-encoded-len/tests/max_encoded_len_ui/literal_list_item.stderr b/max-encoded-len/tests/max_encoded_len_ui/literal_list_item.stderr deleted file mode 100644 index 1182599912992..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/literal_list_item.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: expected a path item, not a literal - --> $DIR/literal_list_item.rs:5:25 - | -5 | #[max_encoded_len_crate("frame_support::max_encoded_len")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0599]: no function or associated item named `max_encoded_len` found for struct `Example` in the current scope - --> $DIR/literal_list_item.rs:9:19 - | -6 | struct Example; - | --------------- function or associated item `max_encoded_len` not found for this -... -9 | let _ = Example::max_encoded_len(); - | ^^^^^^^^^^^^^^^ function or associated item not found in `Example` - | - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following trait defines an item `max_encoded_len`, perhaps you need to implement it: - candidate #1: `MaxEncodedLen` diff --git a/max-encoded-len/tests/max_encoded_len_ui/name_value_attr.rs b/max-encoded-len/tests/max_encoded_len_ui/name_value_attr.rs deleted file mode 100644 index 382310d3a7ddf..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/name_value_attr.rs +++ /dev/null @@ -1,10 +0,0 @@ -use codec::Encode; -use frame_support::max_encoded_len::MaxEncodedLen; - -#[derive(Encode, MaxEncodedLen)] -#[max_encoded_len_crate = "frame_support::max_encoded_len"] -struct Example; - -fn main() { - let _ = Example::max_encoded_len(); -} diff --git a/max-encoded-len/tests/max_encoded_len_ui/name_value_attr.stderr b/max-encoded-len/tests/max_encoded_len_ui/name_value_attr.stderr deleted file mode 100644 index 4949631049bab..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/name_value_attr.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: expect: #[max_encoded_len_crate(path::to::crate)] - --> $DIR/name_value_attr.rs:5:3 - | -5 | #[max_encoded_len_crate = "frame_support::max_encoded_len"] - | ^^^^^^^^^^^^^^^^^^^^^ - -error[E0599]: no function or associated item named `max_encoded_len` found for struct `Example` in the current scope - --> $DIR/name_value_attr.rs:9:19 - | -6 | struct Example; - | --------------- function or associated item `max_encoded_len` not found for this -... -9 | let _ = Example::max_encoded_len(); - | ^^^^^^^^^^^^^^^ function or associated item not found in `Example` - | - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following trait defines an item `max_encoded_len`, perhaps you need to implement it: - candidate #1: `MaxEncodedLen` diff --git a/max-encoded-len/tests/max_encoded_len_ui/name_value_list_item.rs b/max-encoded-len/tests/max_encoded_len_ui/name_value_list_item.rs deleted file mode 100644 index 44f92e8d5d994..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/name_value_list_item.rs +++ /dev/null @@ -1,10 +0,0 @@ -use codec::Encode; -use frame_support::max_encoded_len::MaxEncodedLen; - -#[derive(Encode, MaxEncodedLen)] -#[max_encoded_len_crate(path = "frame_support::max_encoded_len")] -struct Example; - -fn main() { - let _ = Example::max_encoded_len(); -} diff --git a/max-encoded-len/tests/max_encoded_len_ui/name_value_list_item.stderr b/max-encoded-len/tests/max_encoded_len_ui/name_value_list_item.stderr deleted file mode 100644 index 2faa1108c49d7..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/name_value_list_item.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: expect: path::to::crate - --> $DIR/name_value_list_item.rs:5:25 - | -5 | #[max_encoded_len_crate(path = "frame_support::max_encoded_len")] - | ^^^^ - -error[E0599]: no function or associated item named `max_encoded_len` found for struct `Example` in the current scope - --> $DIR/name_value_list_item.rs:9:19 - | -6 | struct Example; - | --------------- function or associated item `max_encoded_len` not found for this -... -9 | let _ = Example::max_encoded_len(); - | ^^^^^^^^^^^^^^^ function or associated item not found in `Example` - | - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following trait defines an item `max_encoded_len`, perhaps you need to implement it: - candidate #1: `MaxEncodedLen` diff --git a/max-encoded-len/tests/max_encoded_len_ui/no_path_list_items.rs b/max-encoded-len/tests/max_encoded_len_ui/no_path_list_items.rs deleted file mode 100644 index 069c8af5a77e5..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/no_path_list_items.rs +++ /dev/null @@ -1,10 +0,0 @@ -use codec::Encode; -use frame_support::max_encoded_len::MaxEncodedLen; - -#[derive(Encode, MaxEncodedLen)] -#[max_encoded_len_crate] -struct Example; - -fn main() { - let _ = Example::max_encoded_len(); -} diff --git a/max-encoded-len/tests/max_encoded_len_ui/no_path_list_items.stderr b/max-encoded-len/tests/max_encoded_len_ui/no_path_list_items.stderr deleted file mode 100644 index 4d36039d33b3c..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/no_path_list_items.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: expect: #[max_encoded_len_crate(path::to::crate)] - --> $DIR/no_path_list_items.rs:5:3 - | -5 | #[max_encoded_len_crate] - | ^^^^^^^^^^^^^^^^^^^^^ - -error[E0599]: no function or associated item named `max_encoded_len` found for struct `Example` in the current scope - --> $DIR/no_path_list_items.rs:9:19 - | -6 | struct Example; - | --------------- function or associated item `max_encoded_len` not found for this -... -9 | let _ = Example::max_encoded_len(); - | ^^^^^^^^^^^^^^^ function or associated item not found in `Example` - | - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following trait defines an item `max_encoded_len`, perhaps you need to implement it: - candidate #1: `MaxEncodedLen` diff --git a/max-encoded-len/tests/max_encoded_len_ui/not_encode.rs b/max-encoded-len/tests/max_encoded_len_ui/not_encode.rs deleted file mode 100644 index 5e8eb6035547a..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/not_encode.rs +++ /dev/null @@ -1,6 +0,0 @@ -use max_encoded_len::MaxEncodedLen; - -#[derive(MaxEncodedLen)] -struct NotEncode; - -fn main() {} diff --git a/max-encoded-len/tests/max_encoded_len_ui/not_encode.stderr b/max-encoded-len/tests/max_encoded_len_ui/not_encode.stderr deleted file mode 100644 index 1e0ead0854a0e..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/not_encode.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error[E0277]: the trait bound `NotEncode: parity_scale_codec::codec::WrapperTypeEncode` is not satisfied - --> $DIR/not_encode.rs:3:10 - | -3 | #[derive(MaxEncodedLen)] - | ^^^^^^^^^^^^^ the trait `parity_scale_codec::codec::WrapperTypeEncode` is not implemented for `NotEncode` - | - ::: $WORKSPACE/max-encoded-len/src/lib.rs - | - | pub trait MaxEncodedLen: Encode { - | ------ required by this bound in `MaxEncodedLen` - | - = note: required because of the requirements on the impl of `parity_scale_codec::codec::Encode` for `NotEncode` - = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/max-encoded-len/tests/max_encoded_len_ui/not_mel.rs b/max-encoded-len/tests/max_encoded_len_ui/not_mel.rs deleted file mode 100644 index cbaf820ff58e3..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/not_mel.rs +++ /dev/null @@ -1,14 +0,0 @@ -use codec::Encode; -use max_encoded_len::MaxEncodedLen; - -#[derive(Encode)] -struct NotMel; - -#[derive(Encode, MaxEncodedLen)] -struct Generic { - t: T, -} - -fn main() { - let _ = Generic::::max_encoded_len(); -} diff --git a/max-encoded-len/tests/max_encoded_len_ui/not_mel.stderr b/max-encoded-len/tests/max_encoded_len_ui/not_mel.stderr deleted file mode 100644 index 0aabd4b2a393b..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/not_mel.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0599]: the function or associated item `max_encoded_len` exists for struct `Generic`, but its trait bounds were not satisfied - --> $DIR/not_mel.rs:13:29 - | -5 | struct NotMel; - | -------------- doesn't satisfy `NotMel: MaxEncodedLen` -... -8 | struct Generic { - | ----------------- - | | - | function or associated item `max_encoded_len` not found for this - | doesn't satisfy `Generic: MaxEncodedLen` -... -13 | let _ = Generic::::max_encoded_len(); - | ^^^^^^^^^^^^^^^ function or associated item cannot be called on `Generic` due to unsatisfied trait bounds - | - = note: the following trait bounds were not satisfied: - `NotMel: MaxEncodedLen` - which is required by `Generic: MaxEncodedLen` - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following trait defines an item `max_encoded_len`, perhaps you need to implement it: - candidate #1: `MaxEncodedLen` diff --git a/max-encoded-len/tests/max_encoded_len_ui/path_attr.rs b/max-encoded-len/tests/max_encoded_len_ui/path_attr.rs deleted file mode 100644 index 069c8af5a77e5..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/path_attr.rs +++ /dev/null @@ -1,10 +0,0 @@ -use codec::Encode; -use frame_support::max_encoded_len::MaxEncodedLen; - -#[derive(Encode, MaxEncodedLen)] -#[max_encoded_len_crate] -struct Example; - -fn main() { - let _ = Example::max_encoded_len(); -} diff --git a/max-encoded-len/tests/max_encoded_len_ui/path_attr.stderr b/max-encoded-len/tests/max_encoded_len_ui/path_attr.stderr deleted file mode 100644 index 84745efc5e6ff..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/path_attr.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: expect: #[max_encoded_len_crate(path::to::crate)] - --> $DIR/path_attr.rs:5:3 - | -5 | #[max_encoded_len_crate] - | ^^^^^^^^^^^^^^^^^^^^^ - -error[E0599]: no function or associated item named `max_encoded_len` found for struct `Example` in the current scope - --> $DIR/path_attr.rs:9:19 - | -6 | struct Example; - | --------------- function or associated item `max_encoded_len` not found for this -... -9 | let _ = Example::max_encoded_len(); - | ^^^^^^^^^^^^^^^ function or associated item not found in `Example` - | - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following trait defines an item `max_encoded_len`, perhaps you need to implement it: - candidate #1: `MaxEncodedLen` diff --git a/max-encoded-len/tests/max_encoded_len_ui/two_path_list_items.rs b/max-encoded-len/tests/max_encoded_len_ui/two_path_list_items.rs deleted file mode 100644 index 2b29648cbaa2d..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/two_path_list_items.rs +++ /dev/null @@ -1,10 +0,0 @@ -use codec::Encode; -use frame_support::max_encoded_len::MaxEncodedLen; - -#[derive(Encode, MaxEncodedLen)] -#[max_encoded_len_crate(max_encoded_len, frame_support::max_encoded_len)] -struct Example; - -fn main() { - let _ = Example::max_encoded_len(); -} diff --git a/max-encoded-len/tests/max_encoded_len_ui/two_path_list_items.stderr b/max-encoded-len/tests/max_encoded_len_ui/two_path_list_items.stderr deleted file mode 100644 index 9252a4065f25e..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/two_path_list_items.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: expected exactly 1 item - --> $DIR/two_path_list_items.rs:5:3 - | -5 | #[max_encoded_len_crate(max_encoded_len, frame_support::max_encoded_len)] - | ^^^^^^^^^^^^^^^^^^^^^ - -error[E0599]: no function or associated item named `max_encoded_len` found for struct `Example` in the current scope - --> $DIR/two_path_list_items.rs:9:19 - | -6 | struct Example; - | --------------- function or associated item `max_encoded_len` not found for this -... -9 | let _ = Example::max_encoded_len(); - | ^^^^^^^^^^^^^^^ function or associated item not found in `Example` - | - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following trait defines an item `max_encoded_len`, perhaps you need to implement it: - candidate #1: `MaxEncodedLen` diff --git a/max-encoded-len/tests/max_encoded_len_ui/union.rs b/max-encoded-len/tests/max_encoded_len_ui/union.rs deleted file mode 100644 index 932c484b9e670..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/union.rs +++ /dev/null @@ -1,10 +0,0 @@ -use codec::Encode; -use max_encoded_len::MaxEncodedLen; - -#[derive(Encode, MaxEncodedLen)] -union Union { - a: u8, - b: u16, -} - -fn main() {} diff --git a/max-encoded-len/tests/max_encoded_len_ui/union.stderr b/max-encoded-len/tests/max_encoded_len_ui/union.stderr deleted file mode 100644 index d09a3f4673e18..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/union.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: Union types are not supported. - --> $DIR/union.rs:5:1 - | -5 | union Union { - | ^^^^^ - -error: Union types are not supported - --> $DIR/union.rs:5:1 - | -5 | union Union { - | ^^^^^ diff --git a/max-encoded-len/tests/max_encoded_len_ui/unsupported_variant.rs b/max-encoded-len/tests/max_encoded_len_ui/unsupported_variant.rs deleted file mode 100644 index 2fa94867471b1..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/unsupported_variant.rs +++ /dev/null @@ -1,12 +0,0 @@ -use codec::Encode; -use max_encoded_len::MaxEncodedLen; - -#[derive(Encode)] -struct NotMel; - -#[derive(Encode, MaxEncodedLen)] -enum UnsupportedVariant { - NotMel(NotMel), -} - -fn main() {} diff --git a/max-encoded-len/tests/max_encoded_len_ui/unsupported_variant.stderr b/max-encoded-len/tests/max_encoded_len_ui/unsupported_variant.stderr deleted file mode 100644 index aa10b5e4cc15e..0000000000000 --- a/max-encoded-len/tests/max_encoded_len_ui/unsupported_variant.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0599]: no function or associated item named `max_encoded_len` found for struct `NotMel` in the current scope - --> $DIR/unsupported_variant.rs:9:9 - | -5 | struct NotMel; - | -------------- function or associated item `max_encoded_len` not found for this -... -9 | NotMel(NotMel), - | ^^^^^^ function or associated item not found in `NotMel` - | - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following trait defines an item `max_encoded_len`, perhaps you need to implement it: - candidate #1: `MaxEncodedLen` From b716a4084b7e0dd0d03ea3a98023d69f008d5b3a Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 21 Jun 2021 16:12:05 +0200 Subject: [PATCH 04/11] Fix test compilation in `pallet-proxy` --- frame/proxy/src/tests.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frame/proxy/src/tests.rs b/frame/proxy/src/tests.rs index a2cb00d0ccc3d..4383fbea00713 100644 --- a/frame/proxy/src/tests.rs +++ b/frame/proxy/src/tests.rs @@ -102,10 +102,7 @@ parameter_types! { pub const AnnouncementDepositBase: u64 = 1; pub const AnnouncementDepositFactor: u64 = 1; } -#[derive( - Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, - max_encoded_len::MaxEncodedLen, -)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen)] pub enum ProxyType { Any, JustTransfer, From 2aae8b5525b0d4f34afbbd5744325bdf95227970 Mon Sep 17 00:00:00 2001 From: Guillaume Thiolliere Date: Mon, 28 Jun 2021 12:22:14 +0200 Subject: [PATCH 05/11] reorganize import (#9186) --- frame/support/procedural/src/storage/storage_struct.rs | 8 ++++---- frame/support/src/hash.rs | 3 +-- frame/support/src/lib.rs | 4 ++-- frame/support/src/storage/bounded_btree_map.rs | 4 ++-- frame/support/src/storage/bounded_btree_set.rs | 4 ++-- frame/support/src/storage/bounded_vec.rs | 4 ++-- frame/support/src/storage/types/double_map.rs | 4 ++-- frame/support/src/storage/types/key.rs | 4 ++-- frame/support/src/storage/types/map.rs | 4 ++-- frame/support/src/storage/types/nmap.rs | 4 ++-- frame/support/src/storage/types/value.rs | 4 ++-- frame/support/src/storage/weak_bounded_vec.rs | 4 ++-- frame/support/src/traits.rs | 3 --- frame/support/src/traits/tokens/currency.rs | 2 +- frame/system/src/lib.rs | 4 ++-- 15 files changed, 28 insertions(+), 32 deletions(-) diff --git a/frame/support/procedural/src/storage/storage_struct.rs b/frame/support/procedural/src/storage/storage_struct.rs index c1af0ee0701fb..338f3a461e8bc 100644 --- a/frame/support/procedural/src/storage/storage_struct.rs +++ b/frame/support/procedural/src/storage/storage_struct.rs @@ -267,7 +267,7 @@ pub fn decl_and_impl(def: &DeclStorageDefExt) -> TokenStream { use #scrate::sp_runtime::SaturatedConversion; let max_size = < - #value_type as #scrate::traits::MaxEncodedLen + #value_type as #scrate::codec::MaxEncodedLen >::max_encoded_len() .saturated_into(); @@ -301,7 +301,7 @@ pub fn decl_and_impl(def: &DeclStorageDefExt) -> TokenStream { >::Hasher::max_len::<#key>(); let max_size = < - #value_type as #scrate::traits::MaxEncodedLen + #value_type as #scrate::codec::MaxEncodedLen >::max_encoded_len() .saturating_add(key_max_size) .saturated_into(); @@ -342,7 +342,7 @@ pub fn decl_and_impl(def: &DeclStorageDefExt) -> TokenStream { >::Hasher2::max_len::<#key2>(); let max_size = < - #value_type as #scrate::traits::MaxEncodedLen + #value_type as #scrate::codec::MaxEncodedLen >::max_encoded_len() .saturating_add(key1_max_size) .saturating_add(key2_max_size) @@ -378,7 +378,7 @@ pub fn decl_and_impl(def: &DeclStorageDefExt) -> TokenStream { >::key_max_encoded_len(); let max_size = < - #value_type as #scrate::traits::MaxEncodedLen + #value_type as #scrate::codec::MaxEncodedLen >::max_encoded_len() .saturating_add(key_max_size) .saturated_into(); diff --git a/frame/support/src/hash.rs b/frame/support/src/hash.rs index 5c4bfb34f5f96..1425760051d25 100644 --- a/frame/support/src/hash.rs +++ b/frame/support/src/hash.rs @@ -17,10 +17,9 @@ //! Hash utilities. -use codec::Codec; +use codec::{Codec, MaxEncodedLen}; use sp_std::prelude::Vec; use sp_io::hashing::{blake2_128, blake2_256, twox_64, twox_128, twox_256}; -use crate::traits::MaxEncodedLen; // This trait must be kept coherent with frame-support-procedural HasherKind usage pub trait Hashable: Sized { diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index cceb4bbd3bd8c..618be0c95234a 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -1274,7 +1274,7 @@ pub mod pallet_prelude { RuntimeDebug, storage, traits::{ Get, Hooks, IsType, GetPalletVersion, EnsureOrigin, PalletInfoAccess, StorageInfoTrait, - ConstU32, GetDefault, MaxEncodedLen, + ConstU32, GetDefault, }, dispatch::{DispatchResultWithPostInfo, Parameter, DispatchError, DispatchResult}, weights::{DispatchClass, Pays, Weight}, @@ -1284,7 +1284,7 @@ pub mod pallet_prelude { }, storage::bounded_vec::BoundedVec, }; - pub use codec::{Encode, Decode}; + pub use codec::{Encode, Decode, MaxEncodedLen}; pub use crate::inherent::{InherentData, InherentIdentifier, ProvideInherent}; pub use sp_runtime::{ traits::{MaybeSerializeDeserialize, Member, ValidateUnsigned}, diff --git a/frame/support/src/storage/bounded_btree_map.rs b/frame/support/src/storage/bounded_btree_map.rs index 0c1994d63a35d..7b3efbfbeee5f 100644 --- a/frame/support/src/storage/bounded_btree_map.rs +++ b/frame/support/src/storage/bounded_btree_map.rs @@ -23,9 +23,9 @@ use sp_std::{ }; use crate::{ storage::StorageDecodeLength, - traits::{Get, MaxEncodedLen}, + traits::Get, }; -use codec::{Encode, Decode}; +use codec::{Encode, Decode, MaxEncodedLen}; /// A bounded map based on a B-Tree. /// diff --git a/frame/support/src/storage/bounded_btree_set.rs b/frame/support/src/storage/bounded_btree_set.rs index 10c2300a08a09..461b1de58ec81 100644 --- a/frame/support/src/storage/bounded_btree_set.rs +++ b/frame/support/src/storage/bounded_btree_set.rs @@ -23,9 +23,9 @@ use sp_std::{ }; use crate::{ storage::StorageDecodeLength, - traits::{Get, MaxEncodedLen}, + traits::Get, }; -use codec::{Encode, Decode}; +use codec::{Encode, Decode, MaxEncodedLen}; /// A bounded set based on a B-Tree. /// diff --git a/frame/support/src/storage/bounded_vec.rs b/frame/support/src/storage/bounded_vec.rs index d1c042b5db17f..589fe0920744d 100644 --- a/frame/support/src/storage/bounded_vec.rs +++ b/frame/support/src/storage/bounded_vec.rs @@ -20,13 +20,13 @@ use sp_std::prelude::*; use sp_std::{convert::TryFrom, fmt, marker::PhantomData}; -use codec::{Encode, Decode, EncodeLike}; +use codec::{Encode, Decode, EncodeLike, MaxEncodedLen}; use core::{ ops::{Deref, Index, IndexMut}, slice::SliceIndex, }; use crate::{ - traits::{Get, MaxEncodedLen}, + traits::Get, storage::{StorageDecodeLength, StorageTryAppend}, }; diff --git a/frame/support/src/storage/types/double_map.rs b/frame/support/src/storage/types/double_map.rs index 2220dab58dc45..fbe6416c9e842 100644 --- a/frame/support/src/storage/types/double_map.rs +++ b/frame/support/src/storage/types/double_map.rs @@ -18,13 +18,13 @@ //! Storage map type. Implements StorageDoubleMap, StorageIterableDoubleMap, //! StoragePrefixedDoubleMap traits and their methods directly. -use codec::{Decode, Encode, EncodeLike, FullCodec}; +use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen}; use crate::{ storage::{ StorageAppend, StorageTryAppend, StorageDecodeLength, StoragePrefixedMap, types::{OptionQuery, QueryKindTrait, OnEmptyGetter}, }, - traits::{GetDefault, StorageInstance, Get, MaxEncodedLen, StorageInfo}, + traits::{GetDefault, StorageInstance, Get, StorageInfo}, }; use frame_metadata::{DefaultByteGetter, StorageEntryModifier}; use sp_arithmetic::traits::SaturatedConversion; diff --git a/frame/support/src/storage/types/key.rs b/frame/support/src/storage/types/key.rs index def800f62c50e..cafb501f9e418 100755 --- a/frame/support/src/storage/types/key.rs +++ b/frame/support/src/storage/types/key.rs @@ -17,8 +17,8 @@ //! Storage key type. -use crate::{hash::{ReversibleStorageHasher, StorageHasher}, traits::MaxEncodedLen}; -use codec::{Encode, EncodeLike, FullCodec}; +use crate::hash::{ReversibleStorageHasher, StorageHasher}; +use codec::{Encode, EncodeLike, FullCodec, MaxEncodedLen}; use paste::paste; use sp_std::prelude::*; diff --git a/frame/support/src/storage/types/map.rs b/frame/support/src/storage/types/map.rs index 311f2f0b2c770..2c122c3046de0 100644 --- a/frame/support/src/storage/types/map.rs +++ b/frame/support/src/storage/types/map.rs @@ -18,13 +18,13 @@ //! Storage map type. Implements StorageMap, StorageIterableMap, StoragePrefixedMap traits and their //! methods directly. -use codec::{FullCodec, Decode, EncodeLike, Encode}; +use codec::{FullCodec, Decode, EncodeLike, Encode, MaxEncodedLen}; use crate::{ storage::{ StorageAppend, StorageTryAppend, StorageDecodeLength, StoragePrefixedMap, types::{OptionQuery, QueryKindTrait, OnEmptyGetter}, }, - traits::{GetDefault, StorageInstance, Get, MaxEncodedLen, StorageInfo}, + traits::{GetDefault, StorageInstance, Get, StorageInfo}, }; use frame_metadata::{DefaultByteGetter, StorageEntryModifier}; use sp_arithmetic::traits::SaturatedConversion; diff --git a/frame/support/src/storage/types/nmap.rs b/frame/support/src/storage/types/nmap.rs index 0678da22ed147..754801f2284d9 100755 --- a/frame/support/src/storage/types/nmap.rs +++ b/frame/support/src/storage/types/nmap.rs @@ -26,9 +26,9 @@ use crate::{ }, KeyGenerator, PrefixIterator, StorageAppend, StorageDecodeLength, StoragePrefixedMap, }, - traits::{Get, GetDefault, StorageInstance, StorageInfo, MaxEncodedLen}, + traits::{Get, GetDefault, StorageInstance, StorageInfo}, }; -use codec::{Decode, Encode, EncodeLike, FullCodec}; +use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen}; use frame_metadata::{DefaultByteGetter, StorageEntryModifier}; use sp_runtime::SaturatedConversion; use sp_std::prelude::*; diff --git a/frame/support/src/storage/types/value.rs b/frame/support/src/storage/types/value.rs index 5b37066fc3942..625ce22735f49 100644 --- a/frame/support/src/storage/types/value.rs +++ b/frame/support/src/storage/types/value.rs @@ -17,13 +17,13 @@ //! Storage value type. Implements StorageValue trait and its method directly. -use codec::{FullCodec, Decode, EncodeLike, Encode}; +use codec::{FullCodec, Decode, EncodeLike, Encode, MaxEncodedLen}; use crate::{ storage::{ StorageAppend, StorageTryAppend, StorageDecodeLength, types::{OptionQuery, QueryKindTrait, OnEmptyGetter}, }, - traits::{GetDefault, StorageInstance, MaxEncodedLen, StorageInfo}, + traits::{GetDefault, StorageInstance, StorageInfo}, }; use frame_metadata::{DefaultByteGetter, StorageEntryModifier}; use sp_arithmetic::traits::SaturatedConversion; diff --git a/frame/support/src/storage/weak_bounded_vec.rs b/frame/support/src/storage/weak_bounded_vec.rs index ca2271df43419..e5a4843000bbf 100644 --- a/frame/support/src/storage/weak_bounded_vec.rs +++ b/frame/support/src/storage/weak_bounded_vec.rs @@ -20,13 +20,13 @@ use sp_std::prelude::*; use sp_std::{convert::TryFrom, fmt, marker::PhantomData}; -use codec::{Encode, Decode}; +use codec::{Encode, Decode, MaxEncodedLen}; use core::{ ops::{Deref, Index, IndexMut}, slice::SliceIndex, }; use crate::{ - traits::{Get, MaxEncodedLen}, + traits::Get, storage::{StorageDecodeLength, StorageTryAppend}, }; diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index f1a5bea7cad5d..ef5391ffbc3c8 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -81,6 +81,3 @@ pub use dispatch::{EnsureOrigin, OriginTrait, UnfilteredDispatchable}; mod voting; pub use voting::{CurrencyToVote, SaturatingCurrencyToVote, U128CurrencyToVote}; - -// for backwards-compatibility with existing imports -pub use codec::MaxEncodedLen; diff --git a/frame/support/src/traits/tokens/currency.rs b/frame/support/src/traits/tokens/currency.rs index a00e99b0c4ac3..7882d04c035bf 100644 --- a/frame/support/src/traits/tokens/currency.rs +++ b/frame/support/src/traits/tokens/currency.rs @@ -22,7 +22,7 @@ use sp_runtime::traits::MaybeSerializeDeserialize; use crate::dispatch::{DispatchResult, DispatchError}; use super::misc::{Balance, WithdrawReasons, ExistenceRequirement}; use super::imbalance::{Imbalance, SignedImbalance}; -use frame_support::traits::MaxEncodedLen; +use codec::MaxEncodedLen; mod reservable; pub use reservable::{ReservableCurrency, NamedReservableCurrency}; diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index ad57bf6a87994..da9e5fabd3a43 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -88,7 +88,7 @@ use frame_support::{ Parameter, storage, traits::{ SortedMembers, Get, PalletInfo, OnNewAccount, OnKilledAccount, HandleLifetime, - StoredMap, EnsureOrigin, OriginTrait, Filter, MaxEncodedLen, + StoredMap, EnsureOrigin, OriginTrait, Filter, }, weights::{ Weight, RuntimeDbWeight, DispatchInfo, DispatchClass, @@ -96,7 +96,7 @@ use frame_support::{ }, dispatch::{DispatchResultWithPostInfo, DispatchResult}, }; -use codec::{Encode, Decode, FullCodec, EncodeLike}; +use codec::{Encode, Decode, FullCodec, EncodeLike, MaxEncodedLen}; #[cfg(feature = "std")] use frame_support::traits::GenesisBuild; From 39d2f689dda3149946480df680049389c968c1ad Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 28 Jun 2021 14:15:28 +0200 Subject: [PATCH 06/11] Fix remaining `MaxEncodedLen` imports --- bin/node/runtime/src/lib.rs | 4 ++-- frame/balances/src/lib.rs | 4 ++-- frame/proxy/src/lib.rs | 4 ++-- frame/support/test/tests/decl_storage.rs | 2 +- frame/support/test/tests/pallet.rs | 5 ++--- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 109a492e2c713..8291e4b6448c3 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -33,7 +33,7 @@ use frame_support::{ }, traits::{ Currency, Imbalance, KeyOwnerProofSystem, OnUnbalanced, LockIdentifier, - U128CurrencyToVote, MaxEncodedLen, + U128CurrencyToVote, }, }; use frame_system::{ @@ -41,7 +41,7 @@ use frame_system::{ limits::{BlockWeights, BlockLength} }; use frame_support::{traits::InstanceFilter, PalletId}; -use codec::{Encode, Decode}; +use codec::{Encode, Decode, MaxEncodedLen}; use sp_core::{ crypto::KeyTypeId, u32_trait::{_1, _2, _3, _4, _5}, diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index 5dccd7da267f2..27b015bc1cce6 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -158,11 +158,11 @@ pub mod weights; use sp_std::prelude::*; use sp_std::{cmp, result, mem, fmt::Debug, ops::BitOr}; -use codec::{Codec, Encode, Decode}; +use codec::{Codec, Encode, Decode, MaxEncodedLen}; use frame_support::{ ensure, WeakBoundedVec, traits::{ - Currency, OnUnbalanced, TryDrop, StoredMap, MaxEncodedLen, + Currency, OnUnbalanced, TryDrop, StoredMap, WithdrawReasons, LockIdentifier, LockableCurrency, ExistenceRequirement, Imbalance, SignedImbalance, ReservableCurrency, Get, ExistenceRequirement::{AllowDeath, KeepAlive}, NamedReservableCurrency, diff --git a/frame/proxy/src/lib.rs b/frame/proxy/src/lib.rs index bc892b65b3774..d4f430a7e8b0b 100644 --- a/frame/proxy/src/lib.rs +++ b/frame/proxy/src/lib.rs @@ -34,7 +34,7 @@ mod benchmarking; pub mod weights; use sp_std::{prelude::*, convert::TryInto}; -use codec::{Encode, Decode}; +use codec::{Encode, Decode, MaxEncodedLen}; use sp_io::hashing::blake2_256; use sp_runtime::{ DispatchResult, @@ -45,7 +45,7 @@ use frame_support::{ dispatch::{DispatchResultWithPostInfo, PostDispatchInfo}, traits::{ Get, ReservableCurrency, Currency, InstanceFilter, OriginTrait, - IsType, IsSubType, MaxEncodedLen, + IsType, IsSubType, }, weights::GetDispatchInfo, }; diff --git a/frame/support/test/tests/decl_storage.rs b/frame/support/test/tests/decl_storage.rs index ef7b577ab6b8d..2bb4087485901 100644 --- a/frame/support/test/tests/decl_storage.rs +++ b/frame/support/test/tests/decl_storage.rs @@ -29,7 +29,7 @@ mod tests { pub trait Config: frame_support_test::Config { type Origin2: codec::Codec + codec::EncodeLike + Default - + frame_support::traits::MaxEncodedLen; + + codec::MaxEncodedLen; } frame_support::decl_storage! { diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 4f1e66a868947..0fa5d1696c582 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -19,7 +19,6 @@ use frame_support::{ weights::{DispatchInfo, DispatchClass, Pays, GetDispatchInfo}, traits::{ GetCallName, OnInitialize, OnFinalize, OnRuntimeUpgrade, GetPalletVersion, OnGenesis, - MaxEncodedLen, }, dispatch::{UnfilteredDispatchable, Parameter}, storage::unhashed, @@ -48,10 +47,10 @@ impl From for u64 { fn from(_t: SomeType6) -> Self { 0u64 } } pub struct SomeType7; impl From for u64 { fn from(_t: SomeType7) -> Self { 0u64 } } -pub trait SomeAssociation1 { type _1: Parameter + MaxEncodedLen; } +pub trait SomeAssociation1 { type _1: Parameter + codec::MaxEncodedLen; } impl SomeAssociation1 for u64 { type _1 = u64; } -pub trait SomeAssociation2 { type _2: Parameter + MaxEncodedLen; } +pub trait SomeAssociation2 { type _2: Parameter + codec::MaxEncodedLen; } impl SomeAssociation2 for u64 { type _2 = u64; } #[frame_support::pallet] From 6719d01a61fb7f7ac427de3bb75156d7016d1a47 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Fri, 2 Jul 2021 21:04:41 +0200 Subject: [PATCH 07/11] Fix remaining old usages of max-encoded-len crate --- frame/contracts/src/chain_extension.rs | 4 ++-- frame/contracts/src/wasm/runtime.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/contracts/src/chain_extension.rs b/frame/contracts/src/chain_extension.rs index 01c362f613a51..e72ab8cf056b0 100644 --- a/frame/contracts/src/chain_extension.rs +++ b/frame/contracts/src/chain_extension.rs @@ -58,8 +58,8 @@ use crate::{ Error, wasm::{Runtime, RuntimeCosts}, }; -use codec::Decode; -use frame_support::{weights::Weight, traits::MaxEncodedLen}; +use codec::{Decode, MaxEncodedLen}; +use frame_support::weights::Weight; use sp_runtime::DispatchError; use sp_std::{ marker::PhantomData, diff --git a/frame/contracts/src/wasm/runtime.rs b/frame/contracts/src/wasm/runtime.rs index 28987bba9d700..8956e3a2b4458 100644 --- a/frame/contracts/src/wasm/runtime.rs +++ b/frame/contracts/src/wasm/runtime.rs @@ -26,9 +26,9 @@ use crate::{ }; use bitflags::bitflags; use pwasm_utils::parity_wasm::elements::ValueType; -use frame_support::{dispatch::DispatchError, ensure, weights::Weight, traits::MaxEncodedLen}; +use frame_support::{dispatch::DispatchError, ensure, weights::Weight}; use sp_std::prelude::*; -use codec::{Decode, DecodeAll, Encode}; +use codec::{Decode, DecodeAll, Encode, MaxEncodedLen}; use sp_core::{Bytes, crypto::UncheckedFrom}; use sp_io::hashing::{ keccak_256, From 2ee55bb4c69dfcd65605add4bf991302058ee061 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 5 Jul 2021 16:20:29 +0200 Subject: [PATCH 08/11] Fix UI test --- .../tests/pallet_ui/call_argument_invalid_bound_2.stderr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.stderr b/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.stderr index bad37153de7c4..1ba613c66d498 100644 --- a/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.stderr +++ b/frame/support/test/tests/pallet_ui/call_argument_invalid_bound_2.stderr @@ -33,9 +33,9 @@ error[E0277]: the trait bound `::Bar: WrapperTypeEncode` is 20 | pub fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { | ^ the trait `WrapperTypeEncode` is not implemented for `::Bar` | - ::: /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/parity-scale-codec-2.1.1/src/codec.rs:216:21 + ::: /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/parity-scale-codec-2.2.0/src/codec.rs:223:21 | -216 | fn encode_to(&self, dest: &mut T) { +223 | fn encode_to(&self, dest: &mut T) { | ------ required by this bound in `encode_to` | = note: required because of the requirements on the impl of `pallet::_::_parity_scale_codec::Encode` for `::Bar` @@ -46,9 +46,9 @@ error[E0277]: the trait bound `::Bar: WrapperTypeDecode` is 20 | pub fn foo(origin: OriginFor, bar: T::Bar) -> DispatchResultWithPostInfo { | ^ the trait `WrapperTypeDecode` is not implemented for `::Bar` | - ::: /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/parity-scale-codec-2.1.1/src/codec.rs:277:18 + ::: /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/parity-scale-codec-2.2.0/src/codec.rs:284:18 | -277 | fn decode(input: &mut I) -> Result; +284 | fn decode(input: &mut I) -> Result; | ----- required by this bound in `pallet::_::_parity_scale_codec::Decode::decode` | = note: required because of the requirements on the impl of `Decode` for `::Bar` From dec27e26222ebd3cfa814a8dfba939dc705da9cb Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 5 Jul 2021 16:28:13 +0200 Subject: [PATCH 09/11] Manually depend on new impl-codec to fix Polkadot companion build --- Cargo.lock | 1 + primitives/core/Cargo.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 462943132a108..36a641fc6dfc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8922,6 +8922,7 @@ dependencies = [ "hash256-std-hasher", "hex", "hex-literal", + "impl-codec", "impl-serde", "lazy_static", "libsecp256k1", diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index a0bed58e8bb52..a1be84afdd772 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -19,6 +19,10 @@ log = { version = "0.4.11", default-features = false } serde = { version = "1.0.101", optional = true, features = ["derive"] } byteorder = { version = "1.3.2", default-features = false } primitive-types = { version = "0.9.0", default-features = false, features = ["codec"] } +# TODO(xanewok): Remove me once we bump primitive-types to 0.10.1. This is to make +# Substrate/Polkadot build happy since it's a transitive dependency that's not +# explicitly used in Substrate but we need the 0.5.1 version to build. +impl-codec = { version = "0.5.1", default-features = false } impl-serde = { version = "0.3.0", optional = true } wasmi = { version = "0.9.0", optional = true } hash-db = { version = "0.15.2", default-features = false } From ed3f555c184c2d9fe9a50a63f864e28e70c9314f Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 5 Jul 2021 17:34:06 +0200 Subject: [PATCH 10/11] Use newly released primitive-types v0.9.1 that has new codec impls --- Cargo.lock | 5 ++--- primitives/core/Cargo.toml | 6 +----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36a641fc6dfc5..2f625bfa7a06c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6244,9 +6244,9 @@ dependencies = [ [[package]] name = "primitive-types" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2415937401cb030a2a0a4d922483f945fa068f52a7dbb22ce0fe5f2b6f6adace" +checksum = "06345ee39fbccfb06ab45f3a1a5798d9dafa04cb8921a76d227040003a234b0e" dependencies = [ "fixed-hash", "impl-codec", @@ -8922,7 +8922,6 @@ dependencies = [ "hash256-std-hasher", "hex", "hex-literal", - "impl-codec", "impl-serde", "lazy_static", "libsecp256k1", diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index a1be84afdd772..cf670404c3461 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -18,11 +18,7 @@ codec = { package = "parity-scale-codec", version = "2.0.0", default-features = log = { version = "0.4.11", default-features = false } serde = { version = "1.0.101", optional = true, features = ["derive"] } byteorder = { version = "1.3.2", default-features = false } -primitive-types = { version = "0.9.0", default-features = false, features = ["codec"] } -# TODO(xanewok): Remove me once we bump primitive-types to 0.10.1. This is to make -# Substrate/Polkadot build happy since it's a transitive dependency that's not -# explicitly used in Substrate but we need the 0.5.1 version to build. -impl-codec = { version = "0.5.1", default-features = false } +primitive-types = { version = "0.9.1", default-features = false, features = ["codec"] } impl-serde = { version = "0.3.0", optional = true } wasmi = { version = "0.9.0", optional = true } hash-db = { version = "0.15.2", default-features = false } From 0ac3e3344036de7fcdfd11ecd920993891adb7ec Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 5 Jul 2021 17:40:48 +0200 Subject: [PATCH 11/11] Make sure codec deps are up-to-date in crates that use them --- bin/node/runtime/Cargo.toml | 2 +- frame/balances/Cargo.toml | 2 +- frame/contracts/Cargo.toml | 2 +- frame/proxy/Cargo.toml | 2 +- frame/support/Cargo.toml | 2 +- frame/timestamp/Cargo.toml | 2 +- primitives/core/Cargo.toml | 2 +- primitives/runtime/Cargo.toml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/node/runtime/Cargo.toml b/bin/node/runtime/Cargo.toml index b1dc58107a6ce..c84c6a07b6395 100644 --- a/bin/node/runtime/Cargo.toml +++ b/bin/node/runtime/Cargo.toml @@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] # third-party dependencies -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ["derive", "max-encoded-len"] } static_assertions = "1.1.0" hex-literal = { version = "0.3.1", optional = true } log = { version = "0.4.14", default-features = false } diff --git a/frame/balances/Cargo.toml b/frame/balances/Cargo.toml index 116a52151583a..724fadf48c52f 100644 --- a/frame/balances/Cargo.toml +++ b/frame/balances/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ["derive", "max-encoded-len"] } sp-std = { version = "3.0.0", default-features = false, path = "../../primitives/std" } sp-runtime = { version = "3.0.0", default-features = false, path = "../../primitives/runtime" } frame-benchmarking = { version = "3.1.0", default-features = false, path = "../benchmarking", optional = true } diff --git a/frame/contracts/Cargo.toml b/frame/contracts/Cargo.toml index 9d344fb6866d7..e9f7236629ab0 100644 --- a/frame/contracts/Cargo.toml +++ b/frame/contracts/Cargo.toml @@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] bitflags = "1.0" -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ["derive", "max-encoded-len"] } log = { version = "0.4", default-features = false } pwasm-utils = { version = "0.18", default-features = false } serde = { version = "1", optional = true, features = ["derive"] } diff --git a/frame/proxy/Cargo.toml b/frame/proxy/Cargo.toml index a4b47dc2b09ba..821d26556c4ea 100644 --- a/frame/proxy/Cargo.toml +++ b/frame/proxy/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false } +codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ["max-encoded-len"] } frame-support = { version = "3.0.0", default-features = false, path = "../support" } frame-system = { version = "3.0.0", default-features = false, path = "../system" } sp-core = { version = "3.0.0", default-features = false, path = "../../primitives/core" } diff --git a/frame/support/Cargo.toml b/frame/support/Cargo.toml index 173e3da27984d..bac78bd29fe19 100644 --- a/frame/support/Cargo.toml +++ b/frame/support/Cargo.toml @@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "2.1.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ["derive", "max-encoded-len"] } frame-metadata = { version = "13.0.0", default-features = false, path = "../metadata" } sp-std = { version = "3.0.0", default-features = false, path = "../../primitives/std" } sp-io = { version = "3.0.0", default-features = false, path = "../../primitives/io" } diff --git a/frame/timestamp/Cargo.toml b/frame/timestamp/Cargo.toml index 05ea8e40c6627..7a57c5e88a6f6 100644 --- a/frame/timestamp/Cargo.toml +++ b/frame/timestamp/Cargo.toml @@ -15,7 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ["derive", "max-encoded-len"] } sp-std = { version = "3.0.0", default-features = false, path = "../../primitives/std" } sp-io = { version = "3.0.0", default-features = false, path = "../../primitives/io", optional = true } sp-runtime = { version = "3.0.0", default-features = false, path = "../../primitives/runtime" } diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index cf670404c3461..3b140d4bfc996 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] sp-std = { version = "3.0.0", default-features = false, path = "../std" } -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ["derive", "max-encoded-len"] } log = { version = "0.4.11", default-features = false } serde = { version = "1.0.101", optional = true, features = ["derive"] } byteorder = { version = "1.3.2", default-features = false } diff --git a/primitives/runtime/Cargo.toml b/primitives/runtime/Cargo.toml index 7d33e7fa62d2d..ba6e0fcf46d6f 100644 --- a/primitives/runtime/Cargo.toml +++ b/primitives/runtime/Cargo.toml @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false, features = ["derive", "max-encoded-len"] } sp-core = { version = "3.0.0", default-features = false, path = "../core" } sp-application-crypto = { version = "3.0.0", default-features = false, path = "../application-crypto" } sp-arithmetic = { version = "3.0.0", default-features = false, path = "../arithmetic" }