From 33def0cfb2877d6cfe6211d225224030cdfeaa81 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Fri, 15 May 2020 19:14:23 +0200 Subject: [PATCH 1/6] Implement codec for ethereum types --- ethbloom/Cargo.toml | 2 ++ ethbloom/src/lib.rs | 9 ++++++--- ethereum-types/Cargo.toml | 2 ++ ethereum-types/src/hash.rs | 12 ++++++++++++ ethereum-types/src/uint.rs | 4 ++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index de61568ce..32229fc74 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -15,6 +15,7 @@ crunchy = { version = "0.2.2", default-features = false, features = ["limit_256" fixed-hash = { path = "../fixed-hash", version = "0.6", default-features = false } impl-serde = { path = "../primitive-types/impls/serde", version = "0.3", default-features = false, optional = true } impl-rlp = { path = "../primitive-types/impls/rlp", version = "0.2", default-features = false } +impl-codec = { version = "0.4.1", path = "../primitive-types/impls/codec", default-features = false, optional = true } [dev-dependencies] criterion = "0.3.0" @@ -27,6 +28,7 @@ std = ["fixed-hash/std", "crunchy/std"] serialize = ["std", "impl-serde"] rustc-hex = ["fixed-hash/rustc-hex"] arbitrary = ["fixed-hash/arbitrary"] +codec = ["impl-codec"] [[bench]] name = "bloom" diff --git a/ethbloom/src/lib.rs b/ethbloom/src/lib.rs index c12f5cab8..ded4e4d64 100644 --- a/ethbloom/src/lib.rs +++ b/ethbloom/src/lib.rs @@ -57,6 +57,8 @@ use fixed_hash::*; use impl_rlp::impl_fixed_hash_rlp; #[cfg(feature = "serialize")] use impl_serde::impl_fixed_hash_serde; +#[cfg(feature = "codec")] +use impl_codec::impl_fixed_hash_codec; use tiny_keccak::{Hasher, Keccak}; // 3 according to yellowpaper @@ -68,6 +70,10 @@ construct_fixed_hash! { pub struct Bloom(BLOOM_SIZE); } impl_fixed_hash_rlp!(Bloom, BLOOM_SIZE); +#[cfg(feature = "serialize")] +impl_fixed_hash_serde!(Bloom, BLOOM_SIZE); +#[cfg(feature = "codec")] +impl_fixed_hash_codec!(Bloom, BLOOM_SIZE); /// Returns log2. fn log2(x: usize) -> u32 { @@ -264,9 +270,6 @@ impl<'a> From<&'a Bloom> for BloomRef<'a> { } } -#[cfg(feature = "serialize")] -impl_fixed_hash_serde!(Bloom, BLOOM_SIZE); - #[cfg(test)] mod tests { use super::{Bloom, Input}; diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index 572ad5530..599702638 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -14,6 +14,7 @@ uint-crate = { path = "../uint", package = "uint", version = "0.8", default-feat primitive-types = { path = "../primitive-types", version = "0.7", features = ["rlp", "byteorder", "rustc-hex"], default-features = false } impl-serde = { path = "../primitive-types/impls/serde", version = "0.3.0", default-features = false, optional = true } impl-rlp = { path = "../primitive-types/impls/rlp", version = "0.2", default-features = false } +impl-codec = { version = "0.4.1", path = "../primitive-types/impls/codec", default-features = false, optional = true } [dev-dependencies] serde_json = "1.0.41" @@ -23,3 +24,4 @@ default = ["std", "serialize"] std = ["uint-crate/std", "fixed-hash/std", "ethbloom/std", "primitive-types/std"] serialize = ["std", "impl-serde", "primitive-types/serde", "ethbloom/serialize"] arbitrary = ["ethbloom/arbitrary", "fixed-hash/arbitrary", "uint-crate/arbitrary"] +codec = ["impl-codec", "ethbloom/codec"] diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index 9e2057dec..dce1129fd 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -11,6 +11,8 @@ use fixed_hash::*; use impl_rlp::impl_fixed_hash_rlp; #[cfg(feature = "serialize")] use impl_serde::impl_fixed_hash_serde; +#[cfg(feature = "codec")] +use impl_codec::impl_fixed_hash_codec; pub trait BigEndianHash { type Uint; @@ -23,16 +25,22 @@ construct_fixed_hash! { pub struct H32(4); } impl_fixed_hash_rlp!(H32, 4); #[cfg(feature = "serialize")] impl_fixed_hash_serde!(H32, 4); +#[cfg(feature = "codec")] +impl_fixed_hash_codec!(H32, 4); construct_fixed_hash! { pub struct H64(8); } impl_fixed_hash_rlp!(H64, 8); #[cfg(feature = "serialize")] impl_fixed_hash_serde!(H64, 8); +#[cfg(feature = "codec")] +impl_fixed_hash_codec!(H64, 8); construct_fixed_hash! { pub struct H128(16); } impl_fixed_hash_rlp!(H128, 16); #[cfg(feature = "serialize")] impl_fixed_hash_serde!(H128, 16); +#[cfg(feature = "codec")] +impl_fixed_hash_codec!(H128, 16); pub use primitive_types::H160; pub use primitive_types::H256; @@ -41,6 +49,8 @@ construct_fixed_hash! { pub struct H264(33); } impl_fixed_hash_rlp!(H264, 33); #[cfg(feature = "serialize")] impl_fixed_hash_serde!(H264, 33); +#[cfg(feature = "codec")] +impl_fixed_hash_codec!(H264, 33); pub use primitive_types::H512; @@ -48,6 +58,8 @@ construct_fixed_hash! { pub struct H520(65); } impl_fixed_hash_rlp!(H520, 65); #[cfg(feature = "serialize")] impl_fixed_hash_serde!(H520, 65); +#[cfg(feature = "codec")] +impl_fixed_hash_codec!(H520, 65); macro_rules! impl_uint_conversions { ($hash: ident, $uint: ident) => { diff --git a/ethereum-types/src/uint.rs b/ethereum-types/src/uint.rs index 87d09541c..d8532e954 100644 --- a/ethereum-types/src/uint.rs +++ b/ethereum-types/src/uint.rs @@ -9,6 +9,8 @@ use impl_rlp::impl_uint_rlp; #[cfg(feature = "serialize")] use impl_serde::impl_uint_serde; +#[cfg(feature = "codec")] +use impl_codec::impl_uint_codec; use uint_crate::*; pub use uint_crate::FromDecStrErr; @@ -20,6 +22,8 @@ construct_uint! { impl_uint_rlp!(U64, 1); #[cfg(feature = "serialize")] impl_uint_serde!(U64, 1); +#[cfg(feature = "codec")] +impl_uint_codec!(U64, 1); pub use primitive_types::{U128, U256, U512}; From 8f040b421e12686c45ac0265be8143f765ba6c5a Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Fri, 15 May 2020 19:16:15 +0200 Subject: [PATCH 2/6] Bump patch version --- ethbloom/Cargo.toml | 2 +- ethereum-types/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 32229fc74..b89f51335 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ethbloom" -version = "0.9.1" +version = "0.9.2" authors = ["Parity Technologies "] description = "Ethereum bloom filter" license = "MIT OR Apache-2.0" diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index 599702638..496a5f88a 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ethereum-types" -version = "0.9.1" +version = "0.9.2" authors = ["Parity Technologies "] license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" From e5885cc7c43ccd6fc9753769d5e826a2a934bb18 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Sun, 17 May 2020 22:58:46 +0200 Subject: [PATCH 3/6] Update changelog for ethbloom and ethereum-types --- ethbloom/CHANGELOG.md | 3 +++ ethereum-types/CHANGELOG.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/ethbloom/CHANGELOG.md b/ethbloom/CHANGELOG.md index cc467dae8..67480095f 100644 --- a/ethbloom/CHANGELOG.md +++ b/ethbloom/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.9.2] - 2020-05-18 +- Added `codec` feature. [#393](https://github.com/paritytech/parity-common/pull/393) + ## [0.9.1] - 2020-04-27 - Added `arbitrary` feature. [#378](https://github.com/paritytech/parity-common/pull/378) diff --git a/ethereum-types/CHANGELOG.md b/ethereum-types/CHANGELOG.md index c91696835..058a2d34c 100644 --- a/ethereum-types/CHANGELOG.md +++ b/ethereum-types/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.9.2] - 2020-05-18 +- Added `codec` feature. [#393](https://github.com/paritytech/parity-common/pull/393) + ## [0.9.1] - 2020-04-27 - Added `arbitrary` feature. [#378](https://github.com/paritytech/parity-common/pull/378) From fd929e05d23614f17bde7b346c7e03f053c559ae Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Sun, 17 May 2020 23:05:39 +0200 Subject: [PATCH 4/6] Fix import order --- ethbloom/src/lib.rs | 4 ++-- ethereum-types/src/hash.rs | 4 ++-- ethereum-types/src/uint.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ethbloom/src/lib.rs b/ethbloom/src/lib.rs index ded4e4d64..7b18ec9ee 100644 --- a/ethbloom/src/lib.rs +++ b/ethbloom/src/lib.rs @@ -54,11 +54,11 @@ use core::{mem, ops}; use crunchy::unroll; use fixed_hash::*; +#[cfg(feature = "codec")] +use impl_codec::impl_fixed_hash_codec; use impl_rlp::impl_fixed_hash_rlp; #[cfg(feature = "serialize")] use impl_serde::impl_fixed_hash_serde; -#[cfg(feature = "codec")] -use impl_codec::impl_fixed_hash_codec; use tiny_keccak::{Hasher, Keccak}; // 3 according to yellowpaper diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index dce1129fd..25f00557d 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -8,11 +8,11 @@ use crate::{U128, U256, U512, U64}; use fixed_hash::*; +#[cfg(feature = "codec")] +use impl_codec::impl_fixed_hash_codec; use impl_rlp::impl_fixed_hash_rlp; #[cfg(feature = "serialize")] use impl_serde::impl_fixed_hash_serde; -#[cfg(feature = "codec")] -use impl_codec::impl_fixed_hash_codec; pub trait BigEndianHash { type Uint; diff --git a/ethereum-types/src/uint.rs b/ethereum-types/src/uint.rs index d8532e954..881e0ecd6 100644 --- a/ethereum-types/src/uint.rs +++ b/ethereum-types/src/uint.rs @@ -6,11 +6,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(feature = "codec")] +use impl_codec::impl_uint_codec; use impl_rlp::impl_uint_rlp; #[cfg(feature = "serialize")] use impl_serde::impl_uint_serde; -#[cfg(feature = "codec")] -use impl_codec::impl_uint_codec; use uint_crate::*; pub use uint_crate::FromDecStrErr; From 72aafd45b0a51e1f1c768a5909d487bb538ba5d3 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Sun, 17 May 2020 23:05:47 +0200 Subject: [PATCH 5/6] Add CI test of --all-features for ethbloom and ethereum-types --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a79ed71d8..0d1edfff6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,4 +60,5 @@ script: - cd rlp/ && cargo test --no-default-features && cargo check --benches && cd .. - cd triehash/ && cargo check --benches && cd .. - cd kvdb-web/ && wasm-pack test --headless --firefox && cd .. - + - cd ethbloom/ && cargo test --all-features + - cd ethereum-types/ && cargo test --all-features From e8940a98681c0740b7df758c1c0b239f8b1efbbf Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Sun, 17 May 2020 23:35:59 +0200 Subject: [PATCH 6/6] Fix CI --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0d1edfff6..ef5f3a01a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,5 +60,5 @@ script: - cd rlp/ && cargo test --no-default-features && cargo check --benches && cd .. - cd triehash/ && cargo check --benches && cd .. - cd kvdb-web/ && wasm-pack test --headless --firefox && cd .. - - cd ethbloom/ && cargo test --all-features - - cd ethereum-types/ && cargo test --all-features + - cd ethbloom/ && cargo test --all-features && cd .. + - cd ethereum-types/ && cargo test --all-features && cd ..