Remove in-tree max-encoded-len and use the new SCALE codec crate instead (#9163)

* Update impl-codec to use new upstream MaxEncodedLen trait

* Adapt crates to use the updated codec crate for `MaxEncodedLen`

* Remove max-encoded-len crate altogether

* Fix test compilation in `pallet-proxy`

* reorganize import (#9186)

* Fix remaining `MaxEncodedLen` imports

* Fix remaining old usages of max-encoded-len crate

* Fix UI test

* Manually depend on new impl-codec to fix Polkadot companion build

* Use newly released primitive-types v0.9.1 that has new codec impls

* Make sure codec deps are up-to-date in crates that use them

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Igor Matuszewski
2021-07-05 22:37:24 +02:00
committed by GitHub
parent b61dd3e8c5
commit eb6d651f9c
70 changed files with 72 additions and 1037 deletions
+8 -38
View File
@@ -1853,7 +1853,6 @@ dependencies = [
"frame-system",
"impl-trait-for-tuples",
"log",
"max-encoded-len",
"once_cell",
"parity-scale-codec",
"parity-util-mem",
@@ -2712,9 +2711,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",
]
@@ -3766,29 +3765,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"
@@ -4374,7 +4350,6 @@ dependencies = [
"frame-try-runtime",
"hex-literal",
"log",
"max-encoded-len",
"node-primitives",
"pallet-assets",
"pallet-authority-discovery",
@@ -4726,7 +4701,6 @@ dependencies = [
"frame-benchmarking",
"frame-support",
"frame-system",
"max-encoded-len",
"pallet-balances",
"parity-scale-codec",
"sp-core",
@@ -4837,7 +4811,6 @@ dependencies = [
"frame-support",
"frame-system",
"log",
"max-encoded-len",
"pallet-transaction-payment",
"parity-scale-codec",
"sp-core",
@@ -5364,7 +5337,6 @@ dependencies = [
"frame-benchmarking",
"frame-support",
"frame-system",
"max-encoded-len",
"pallet-balances",
"pallet-utility",
"parity-scale-codec",
@@ -5774,24 +5746,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",
@@ -8739,7 +8712,6 @@ dependencies = [
name = "sp-application-crypto"
version = "3.0.0"
dependencies = [
"max-encoded-len",
"parity-scale-codec",
"serde",
"sp-core",
@@ -8951,7 +8923,6 @@ dependencies = [
"lazy_static",
"libsecp256k1",
"log",
"max-encoded-len",
"merlin",
"num-traits",
"parity-scale-codec",
@@ -9178,7 +9149,6 @@ dependencies = [
"hash256-std-hasher",
"impl-trait-for-tuples",
"log",
"max-encoded-len",
"parity-scale-codec",
"parity-util-mem",
"paste 1.0.4",
-3
View File
@@ -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
+1 -4
View File
@@ -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 }
@@ -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",
+2 -2
View File
@@ -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},
-2
View File
@@ -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",
+1 -3
View File
@@ -13,14 +13,13 @@ 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 }
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"]
+2 -2
View File
@@ -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,
+1 -1
View File
@@ -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"] }
@@ -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,
@@ -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,
+1 -3
View File
@@ -13,14 +13,13 @@ 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" }
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",
+2 -2
View File
@@ -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,
};
+1 -4
View File
@@ -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,
+1 -3
View File
@@ -14,9 +14,8 @@ 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" }
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 = []
@@ -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();
+1 -2
View File
@@ -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 {
+2 -6
View File
@@ -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},
@@ -2376,7 +2376,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;
@@ -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.
///
@@ -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.
///
@@ -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},
};
@@ -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;
@@ -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::*;
@@ -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;
@@ -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::*;
@@ -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;
@@ -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},
};
-3
View File
@@ -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 max_encoded_len::MaxEncodedLen;
@@ -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};
@@ -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! {
+2 -3
View File
@@ -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<SomeType6> for u64 { fn from(_t: SomeType6) -> Self { 0u64 } }
pub struct SomeType7;
impl From<SomeType7> 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]
@@ -33,9 +33,9 @@ error[E0277]: the trait bound `<T as pallet::Config>::Bar: WrapperTypeEncode` is
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^ the trait `WrapperTypeEncode` is not implemented for `<T as pallet::Config>::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<T: Output + ?Sized>(&self, dest: &mut T) {
223 | fn encode_to<T: Output + ?Sized>(&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 `<T as pallet::Config>::Bar`
@@ -46,9 +46,9 @@ error[E0277]: the trait bound `<T as pallet::Config>::Bar: WrapperTypeDecode` is
20 | pub fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^ the trait `WrapperTypeDecode` is not implemented for `<T as pallet::Config>::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<I: Input>(input: &mut I) -> Result<Self, Error>;
284 | fn decode<I: Input>(input: &mut I) -> Result<Self, Error>;
| ----- required by this bound in `pallet::_::_parity_scale_codec::Decode::decode`
|
= note: required because of the requirements on the impl of `Decode` for `<T as pallet::Config>::Bar`
+2 -2
View File
@@ -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;
+1 -1
View File
@@ -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" }
-36
View File
@@ -1,36 +0,0 @@
[package]
name = "max-encoded-len"
version = "3.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
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.10.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",
]
@@ -1,25 +0,0 @@
[package]
name = "max-encoded-len-derive"
version = "3.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
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 = []
-204
View File
@@ -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<syn::Ident, Error> {
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<TraitBound> {
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::<Result<Vec<_>, _>>()?);
// we have to return `Result<Ident, Error>` here in order to satisfy the trait
// bounds for `.or_else` for `generate_crate_access_2018`, even though `Option<Ident>`
// 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<dyn Iterator<Item = &Type>> = 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(<type of first field>::max_encoded_len())
// .saturating_add(<type of second field>::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(<variant expression>)
// .max(<variant expression>)
// .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()
}
}
}
-161
View File
@@ -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<T: MaxEncodedLen, const N: usize> MaxEncodedLen for [T; N] {
fn max_encoded_len() -> usize {
T::max_encoded_len().saturating_mul(N)
}
}
impl<T: MaxEncodedLen> MaxEncodedLen for Option<T> {
fn max_encoded_len() -> usize {
T::max_encoded_len().saturating_add(1)
}
}
impl<T, E> MaxEncodedLen for Result<T, E>
where
T: MaxEncodedLen,
E: MaxEncodedLen,
{
fn max_encoded_len() -> usize {
T::max_encoded_len().max(E::max_encoded_len()).saturating_add(1)
}
}
impl<T> MaxEncodedLen for PhantomData<T> {
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);
);
}
@@ -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<T> {
one: T,
two: T,
}
#[test]
fn generic_max_length() {
assert_eq!(Generic::<u8>::max_encoded_len(), u8::max_encoded_len() * 2);
assert_eq!(Generic::<u32>::max_encoded_len(), u32::max_encoded_len() * 2);
}
#[derive(Encode, MaxEncodedLen)]
struct TwoGenerics<T, U> {
t: T,
u: U,
}
#[test]
fn two_generics_max_length() {
assert_eq!(
TwoGenerics::<u8, u16>::max_encoded_len(),
u8::max_encoded_len() + u16::max_encoded_len()
);
assert_eq!(
TwoGenerics::<Compact<u64>, [u16; 8]>::max_encoded_len(),
Compact::<u64>::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, T);
#[test]
fn tuple_generic_max_length() {
assert_eq!(TupleGeneric::<u8>::max_encoded_len(), u8::max_encoded_len() * 2);
assert_eq!(TupleGeneric::<u32>::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());
}
@@ -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");
}
@@ -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();
}
@@ -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`
@@ -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();
}
@@ -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`
@@ -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();
}
@@ -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`
@@ -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();
}
@@ -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`
@@ -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();
}
@@ -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`
@@ -1,6 +0,0 @@
use max_encoded_len::MaxEncodedLen;
#[derive(MaxEncodedLen)]
struct NotEncode;
fn main() {}
@@ -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)
@@ -1,14 +0,0 @@
use codec::Encode;
use max_encoded_len::MaxEncodedLen;
#[derive(Encode)]
struct NotMel;
#[derive(Encode, MaxEncodedLen)]
struct Generic<T> {
t: T,
}
fn main() {
let _ = Generic::<NotMel>::max_encoded_len();
}
@@ -1,21 +0,0 @@
error[E0599]: the function or associated item `max_encoded_len` exists for struct `Generic<NotMel>`, but its trait bounds were not satisfied
--> $DIR/not_mel.rs:13:29
|
5 | struct NotMel;
| -------------- doesn't satisfy `NotMel: MaxEncodedLen`
...
8 | struct Generic<T> {
| -----------------
| |
| function or associated item `max_encoded_len` not found for this
| doesn't satisfy `Generic<NotMel>: MaxEncodedLen`
...
13 | let _ = Generic::<NotMel>::max_encoded_len();
| ^^^^^^^^^^^^^^^ function or associated item cannot be called on `Generic<NotMel>` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`NotMel: MaxEncodedLen`
which is required by `Generic<NotMel>: 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`
@@ -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();
}
@@ -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`
@@ -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();
}
@@ -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`
@@ -1,10 +0,0 @@
use codec::Encode;
use max_encoded_len::MaxEncodedLen;
#[derive(Encode, MaxEncodedLen)]
union Union {
a: u8,
b: u16,
}
fn main() {}
@@ -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 {
| ^^^^^
@@ -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() {}
@@ -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`
@@ -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
@@ -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);
}
+1 -3
View File
@@ -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 }
@@ -40,7 +40,6 @@ parity-util-mem = { version = "0.10.0", default-features = false, features = ["p
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
+1 -2
View File
@@ -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")]
+2 -2
View File
@@ -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 {
+2 -2
View File
@@ -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]);
+2 -2
View File
@@ -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]);
+1 -3
View File
@@ -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" }
@@ -29,7 +29,6 @@ impl-trait-for-tuples = "0.2.1"
parity-util-mem = { version = "0.10.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",
]
+1 -2
View File
@@ -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<T: ?Sized> {