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

Commit

Permalink
Remove in-tree max-encoded-len and use the new SCALE codec crate in…
Browse files Browse the repository at this point in the history
…stead (#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>
  • Loading branch information
Xanewok and gui1117 authored Jul 5, 2021
1 parent 32a365d commit d22f0df
Show file tree
Hide file tree
Showing 70 changed files with 72 additions and 1,037 deletions.
46 changes: 8 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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" }

Expand Down Expand Up @@ -166,7 +164,6 @@ std = [
"log/std",
"frame-try-runtime/std",
"sp-npos-elections/std",
"max-encoded-len/std",
]
runtime-benchmarks = [
"frame-benchmarking",
Expand Down
4 changes: 2 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ use frame_support::{
},
traits::{
Currency, Imbalance, KeyOwnerProofSystem, OnUnbalanced, LockIdentifier,
U128CurrencyToVote, MaxEncodedLen,
U128CurrencyToVote,
},
};
use frame_system::{
EnsureRoot, EnsureOneOf,
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},
Expand Down
2 changes: 0 additions & 2 deletions frame/assets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -39,7 +38,6 @@ std = [
"frame-support/std",
"frame-system/std",
"frame-benchmarking/std",
"max-encoded-len/std",
]
runtime-benchmarks = [
"frame-benchmarking",
Expand Down
4 changes: 1 addition & 3 deletions frame/balances/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"]
4 changes: 2 additions & 2 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 2 additions & 2 deletions frame/contracts/src/chain_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions frame/proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -38,7 +37,6 @@ std = [
"frame-system/std",
"sp-std/std",
"sp-io/std",
"max-encoded-len/std",
]
runtime-benchmarks = [
"frame-benchmarking",
Expand Down
4 changes: 2 additions & 2 deletions frame/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -45,7 +45,7 @@ use frame_support::{
dispatch::{DispatchResultWithPostInfo, PostDispatchInfo},
traits::{
Get, ReservableCurrency, Currency, InstanceFilter, OriginTrait,
IsType, IsSubType, MaxEncodedLen,
IsType, IsSubType,
},
weights::GetDispatchInfo,
};
Expand Down
5 changes: 1 addition & 4 deletions frame/proxy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions frame/support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -56,7 +55,6 @@ std = [
"sp-state-machine",
"frame-support-procedural/std",
"log/std",
"max-encoded-len/std",
]
runtime-benchmarks = []
try-runtime = []
8 changes: 4 additions & 4 deletions frame/support/procedural/src/storage/storage_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions frame/support/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit d22f0df

Please sign in to comment.