From 687c04d466d0a077d4a11dce601f95a4d0698397 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Wed, 15 Jan 2020 00:24:58 +0100 Subject: [PATCH 01/56] keccak-hash: switch benches to criterion (#315) * keccak-hash: upgrade benches to criterion * ci: cargo check --all --benches * cargo fix --edition-idioms * cargo fmt * upgrade docs to 2018 edition * Revert "cargo fix --edition-idioms" This reverts commit de30cd7c8284890d62cc5b0b5438a32b3116a477. * fixed-hash: update README to 2018 edition * Update keccak-hash/benches/keccak_256.rs Co-Authored-By: David Co-authored-by: David --- .travis.yml | 1 + ethbloom/src/lib.rs | 69 ++++++------ fixed-hash/README.md | 5 +- fixed-hash/src/hash.rs | 26 ++--- fixed-hash/src/lib.rs | 3 - keccak-hash/Cargo.toml | 1 + keccak-hash/benches/keccak_256.rs | 47 ++++---- kvdb-rocksdb/Cargo.toml | 1 + parity-crypto/benches/bench.rs | 5 +- primitive-types/impls/serde/src/serialize.rs | 4 +- rlp/src/lib.rs | 24 ++-- rlp/src/stream.rs | 110 ++++++++----------- triehash/src/lib.rs | 61 ++++------ 13 files changed, 145 insertions(+), 212 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3b9bbf6e6..bf3a27276 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,7 @@ script: cargo fmt -- --check; fi - cargo check --all --tests + - cargo check --all --benches - cargo build --all - cargo test --all --exclude uint --exclude fixed-hash - if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then diff --git a/ethbloom/src/lib.rs b/ethbloom/src/lib.rs index 9ef11e3ee..49a18214f 100644 --- a/ethbloom/src/lib.rs +++ b/ethbloom/src/lib.rs @@ -1,45 +1,42 @@ //! -//! ```rust -//! extern crate ethbloom; -//! #[macro_use] extern crate hex_literal; +//! ``` +//! use hex_literal::hex; //! use ethbloom::{Bloom, Input}; //! -//! fn main() { -//! use std::str::FromStr; -//! let bloom = Bloom::from_str( -//! "00000000000000000000000000000000\ -//! 00000000100000000000000000000000\ -//! 00000000000000000000000000000000\ -//! 00000000000000000000000000000000\ -//! 00000000000000000000000000000000\ -//! 00000000000000000000000000000000\ -//! 00000002020000000000000000000000\ -//! 00000000000000000000000800000000\ -//! 10000000000000000000000000000000\ -//! 00000000000000000000001000000000\ -//! 00000000000000000000000000000000\ -//! 00000000000000000000000000000000\ -//! 00000000000000000000000000000000\ -//! 00000000000000000000000000000000\ -//! 00000000000000000000000000000000\ -//! 00000000000000000000000000000000" -//! ).unwrap(); -//! let address = hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106"); -//! let topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc"); +//! use std::str::FromStr; +//! let bloom = Bloom::from_str( +//! "00000000000000000000000000000000\ +//! 00000000100000000000000000000000\ +//! 00000000000000000000000000000000\ +//! 00000000000000000000000000000000\ +//! 00000000000000000000000000000000\ +//! 00000000000000000000000000000000\ +//! 00000002020000000000000000000000\ +//! 00000000000000000000000800000000\ +//! 10000000000000000000000000000000\ +//! 00000000000000000000001000000000\ +//! 00000000000000000000000000000000\ +//! 00000000000000000000000000000000\ +//! 00000000000000000000000000000000\ +//! 00000000000000000000000000000000\ +//! 00000000000000000000000000000000\ +//! 00000000000000000000000000000000" +//! ).unwrap(); +//! let address = hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106"); +//! let topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc"); //! -//! let mut my_bloom = Bloom::default(); -//! assert!(!my_bloom.contains_input(Input::Raw(&address))); -//! assert!(!my_bloom.contains_input(Input::Raw(&topic))); +//! let mut my_bloom = Bloom::default(); +//! assert!(!my_bloom.contains_input(Input::Raw(&address))); +//! assert!(!my_bloom.contains_input(Input::Raw(&topic))); //! -//! my_bloom.accrue(Input::Raw(&address)); -//! assert!(my_bloom.contains_input(Input::Raw(&address))); -//! assert!(!my_bloom.contains_input(Input::Raw(&topic))); +//! my_bloom.accrue(Input::Raw(&address)); +//! assert!(my_bloom.contains_input(Input::Raw(&address))); +//! assert!(!my_bloom.contains_input(Input::Raw(&topic))); //! -//! my_bloom.accrue(Input::Raw(&topic)); -//! assert!(my_bloom.contains_input(Input::Raw(&address))); -//! assert!(my_bloom.contains_input(Input::Raw(&topic))); -//! assert_eq!(my_bloom, bloom); -//! } +//! my_bloom.accrue(Input::Raw(&topic)); +//! assert!(my_bloom.contains_input(Input::Raw(&address))); +//! assert!(my_bloom.contains_input(Input::Raw(&topic))); +//! assert_eq!(my_bloom, bloom); //! ``` //! diff --git a/fixed-hash/README.md b/fixed-hash/README.md index 19f4c79f9..c07db2f23 100644 --- a/fixed-hash/README.md +++ b/fixed-hash/README.md @@ -7,7 +7,7 @@ Provides macros to construct custom fixed-size hash types. Simple 256 bit (32 bytes) hash type. ```rust -#[macro_use] extern crate fixed_hash; +use fixed_hash::construct_fixed_hash; construct_fixed_hash! { /// My 256 bit hash type. @@ -30,9 +30,6 @@ assert_eq!(H160::from(H256::zero()), H160::zero()); It is possible to add attributes to your types, for example to make them serializable. ```rust -extern crate serde; -#[macro_use] extern crate serde_derive; - construct_fixed_hash!{ /// My serializable hash type. #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] diff --git a/fixed-hash/src/hash.rs b/fixed-hash/src/hash.rs index 25098b5ad..ea2210076 100644 --- a/fixed-hash/src/hash.rs +++ b/fixed-hash/src/hash.rs @@ -13,38 +13,30 @@ /// Create a public unformatted hash type with 32 bytes size. /// /// ``` -/// # #[macro_use] extern crate fixed_hash; +/// use fixed_hash::construct_fixed_hash; +/// /// construct_fixed_hash!{ pub struct H256(32); } -/// # fn main() { -/// # assert_eq!(std::mem::size_of::(), 32); -/// # } +/// assert_eq!(std::mem::size_of::(), 32); /// ``` /// /// With additional attributes and doc comments. /// /// ``` -/// # #[macro_use] extern crate fixed_hash; -/// // Add the below two lines to import serde and its derive -/// // extern crate serde; -/// // #[macro_use] extern crate serde_derive; +/// use fixed_hash::construct_fixed_hash; /// construct_fixed_hash!{ /// /// My unformatted 160 bytes sized hash type. /// #[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] /// pub struct H160(20); /// } -/// # fn main() { -/// # assert_eq!(std::mem::size_of::(), 20); -/// # } +/// assert_eq!(std::mem::size_of::(), 20); /// ``` /// /// The visibility modifier is optional and you can create a private hash type. /// /// ``` -/// # #[macro_use] extern crate fixed_hash; +/// use fixed_hash::construct_fixed_hash; /// construct_fixed_hash!{ struct H512(64); } -/// # fn main() { -/// # assert_eq!(std::mem::size_of::(), 64); -/// # } +/// assert_eq!(std::mem::size_of::(), 64); /// ``` #[macro_export(local_inner_macros)] macro_rules! construct_fixed_hash { @@ -761,15 +753,13 @@ macro_rules! impl_ops_for_hash { /// # Example /// /// ``` -/// #[macro_use] extern crate fixed_hash; +/// use fixed_hash::{construct_fixed_hash, impl_fixed_hash_conversions}; /// construct_fixed_hash!{ struct H160(20); } /// construct_fixed_hash!{ struct H256(32); } /// impl_fixed_hash_conversions!(H256, H160); /// // now use it! -/// # fn main() { /// assert_eq!(H256::from(H160::zero()), H256::zero()); /// assert_eq!(H160::from(H256::zero()), H160::zero()); -/// # } /// ``` #[macro_export(local_inner_macros)] macro_rules! impl_fixed_hash_conversions { diff --git a/fixed-hash/src/lib.rs b/fixed-hash/src/lib.rs index bfc210a84..a3e7af6f7 100644 --- a/fixed-hash/src/lib.rs +++ b/fixed-hash/src/lib.rs @@ -54,9 +54,6 @@ pub use rand; #[doc(hidden)] pub use quickcheck; -#[cfg(test)] -extern crate rand_xorshift; - #[macro_use] mod hash; diff --git a/keccak-hash/Cargo.toml b/keccak-hash/Cargo.toml index 14b6b19ba..3d7d88943 100644 --- a/keccak-hash/Cargo.toml +++ b/keccak-hash/Cargo.toml @@ -14,6 +14,7 @@ primitive-types = { path = "../primitive-types", version = "0.6", default-featur [dev-dependencies] tempdir = "0.3.7" +criterion = "0.3.0" [features] default = ["std"] diff --git a/keccak-hash/benches/keccak_256.rs b/keccak-hash/benches/keccak_256.rs index 5cf5f2526..5c5794bf5 100644 --- a/keccak-hash/benches/keccak_256.rs +++ b/keccak-hash/benches/keccak_256.rs @@ -14,37 +14,36 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -#![feature(test)] - -extern crate test; - +use criterion::{black_box, criterion_group, criterion_main, Criterion}; use keccak_hash::keccak; -use test::Bencher; -#[bench] -fn bench_keccak_256_with_empty_input(b: &mut Bencher) { +criterion_group!(keccak_256, keccak_256_with_empty_input, keccak_256_with_typical_input, keccak_256_with_large_input,); +criterion_main!(keccak_256); + +pub fn keccak_256_with_empty_input(c: &mut Criterion) { let empty = [0u8; 0]; - b.bytes = empty.len() as u64; - b.iter(|| { - let _out = keccak(empty); - }) + c.bench_function("keccak_256_with_empty_input", |b| { + b.iter(|| { + let _out = keccak(black_box(empty)); + }) + }); } -#[bench] -fn bench_keccak_256_with_typical_input(b: &mut Bencher) { - let data: Vec = From::from("some medum length string with important information"); - b.bytes = data.len() as u64; - b.iter(|| { - let _out = keccak(&data); - }) +pub fn keccak_256_with_typical_input(c: &mut Criterion) { + let data: Vec = From::from("some medium length string with important information"); + c.bench_function("keccak_256_with_typical_input", |b| { + b.iter(|| { + let _out = keccak(black_box(&data)); + }) + }); } -#[bench] -fn bench_keccak_256_with_large_input(b: &mut Bencher) { +pub fn keccak_256_with_large_input(c: &mut Criterion) { // 4096 chars let data: Vec = From::from("IGxcKBr1Qp7tuqtpSVhAbvt7UgWLEi7mCA6Wa185seLSIJLFS8K1aAFO9AwtO9b3n9SM3Qg136JMmy9Mj9gZ84IaUm8XioPtloabFDU5ZR1wvauJT6jNTkvBVBpUigIsyU7C1u3s99vKP64LpXqvo1hwItZKtISxmUAgzzjv5q14V4G9bkKAnmc4M5xixgLsDGZmnj6HcOMY3XRkWtxN3RscSKwPA0bfpgtz27ZVHplbXwloYRgRLpjRhZJc7sqO8RFnTHKasVkxVRcUoDBvWNJK27TbLvQQcfxETI2Q1H6c2cBAchi8unSiuxqy5rIvVxcl9rsmmRY4IXLEG9qKntUGbiIRLjEffIP9ODoWog0GbWLmMtfvtf24hWVwXz6Ap5oUAR0kLgb7HYIYrOwKjvfV25iEF7GW8cjhl8yowXx1zcgW4t6NJNqJlGzRKx8MvRWQXvHz8h8JxcHl7S64i6PAkxI9eCLXLvs8cpbEQQHt05Zu6GKm6IInjc9mSh52WFuGhgjbno69XzfkBufJs6c9tZuBf6ErVPj4UxmT82ajCruDusk79Tlvb8oQMLjoplQc1alQaLQwSsMac9iVp9MiE3PeYnTTepJ1V10tp79fciDAnNPJgPcRfDYv0REcSFgR9Q7yWhbpPpyBjO7HwOykDQVGtV0ZbDFrFRygLAXagAIkOPc9HDfcBNID1Q2MGk8ijVWMyvmGz1wzbpNfFcQaSOm8olhwoLyHUGvkyXegh44iNsPBUvSicNxTTDowtMqO5azleuWEjzxCobYbASDopvl6JeJjRtEBBO5YCQJiHsYjlXh9QR5Q543GsqhzRLgcHNRSZYLMZqDmIABXZi8VRNJMZyWXDRKHOGDmcHWe55uZomW6FnyU0uSRKxxz66K0JWfxuFzzxAR0vR4ZZCTemgDRQuDwL1loC3KUMjDpU13jUgoPc4UJUVfwQ4f4BUY3X51Cfw9FLw4oX39KoFoiCP2Z6z27gZUY1IlE59WoXGLj4KjTp4C16ZihG080gfDIWlXnDEk3VwBuBFyKWARB63sGLrGnn27b1gHWMaop6sPvkQgWxkEKIqsxDIvXLZJg2s23V8Gqtt0FeA7R3RCvBysF4jNjQ7NiQTIQWQZ8G9gO4mEsftolSZv6FlSpNeBKIIwYWSO2R6vkgeiz06euE9bwwnenOjwPNGTGk8WHIOZBJ1hIP0ejVU2i2ca9ON0phSAnewqjo5W3PtZf2Q7mDvp9imuVWoy4t8XcZq8I2Un9jVjes9Xi0FLN2t71vLFWLWZmGDzwXxpqEgkARS1WjtJoYXCBmRnXEPj6jQfwMZWKPYSIrmOogxMVoWvA8wrof6utfJna9JezyTnrBJSCuGTSNmwwAXRLoFYxF1RITyN8mI2KmHSfvLXBrbE6kmAkjsm4XJb6kria7oUQQ1gzJuCyB7oNHjZTBFNhNa7VeQ1s1xLOwZXLOAjZ4MDTYKnF7giGJGyswb5KQxkOV9orbuAu6pJsjtql6h1UD3BcNUkG3oz8kJNepbuCN3vNCJcZOX1VrQi0PWkDwyvECrQ2E1CgbU6GpWatpg2sCTpo9W62pCcWBK2FKUFWqU3qo2T7T1Mk2ZtM6hE9I8op0M7xlGE91Mn7ea6aq93MWp7nvFlBvbaMIoeU4MpDx0BeOSkROY03ZBJ0x7K8nJrNUhAtvxp17c9oFk0VxLiuRbAAcwDUormOmpVXZNIcqnap4twEVYaSIowfcNojyUSrFL5nPc8ZG93WgNNl9rpUPZhssVml3DvXghI80A9SW3QauzohTQAX2bkWelFBHnuG2LKrsJ8en51N6CkjcS5b87y1DVMZELcZ1n5s8PCAA1wyn7OSZlgw00GRzch1YwMoHzBBgIUtMO9HrMyuhgqIPJP7KcKbQkKhtvBXKplX8SCfSlOwUkLwHNKm3HYVE0uVfJ91NAsUrGoCOjYiXYpoRT8bjAPWTm6fDlTq2sbPOyTMoc4xRasmiOJ7B0PT6UxPzCPImM4100sPFxp7Kofv4okKZWTPKTefeYiPefI3jRgfDtEIP9E6a35LZD75lBNMXYlAqL3qlnheUQD1WQimFTHiDsW6bmURptNvtkMjEXzXzpWbnyxBskUGTvP2YQjtSAhWliDXkv6t1x71cYav7TQbqvbIzMRQQsguSGYMbs8YIC4DC9ep5reWAfanlTxcxksbEhQ7FGzXOvcufeGnDl2C85gWfryVzwN7kOZiSEktFMOQ1ngRC23y1fCOiHQVQJ2nLnaW7GILb9wkN1mBTRuHsOefRJST0TnRxcn4bBq4MIibIitVyjPRy7G5XvPEcL4pFaW1HCPGm6pUOEEwTer32JObNGCyTFB1BI2cRLJu5BHPjgG3mmb0gGkGlIfh8D2b2amogpivqEn2r9Y1KOKQ8ufJvG2mYfkevco9DuEZ9Nmzkm6XkCTZaFMNHqbfQaKqsEYK7i2N1KfkBct1leW2H9MQ9QO7AHCqXHK47b1kWVIm6pSJA1yV4funzCqXnIJCEURQgHiKf38YpN7ylLhe1J4UvSG3KeesZNeFFIZOEP9HZUSFMpnN1MOrwejojK0D4qzwucYWtXrTQ8I7UP5QhlijIsCKckUa9C1Osjrq8cgSclYNGt19wpy0onUbX1rOQBUlAAUJs4CyXNU0wmVUjw7tG1LUC8my4s9KZDUj4R5UcPz3VaZRrx1RqYu6YxjroJW70I1LyG4WEiQbOkCoLmaiWo9WzbUS2cErlOo2RPymlkWHxbNnZawX2Bc872ivRHSWqNpRHyuR5QewXmcyghH3EhESBAxTel5E2xuQXfLCEVK0kEk0Mj22KPsckKKyH7sVYC1F4YItQh5hj9Titb7KflQb9vnXQ44UHxY3zBhTQT5PSYv1Kv8HxXCsnpmhZCiBru16iX9oEB33icBVB2KKcZZEEKnCGPVxJlM9RTlyNyQmjHf7z4GeTDuMAUrsMO31WvgZBnWcAOtn6ulBTUCAaqxJiWqzlMx2FSANAlyAjAxqzmQjzPLvQRjskUnBFN3woKB1m2bSo2c5thwA1fKiPvN5LW8tl1rnfNy3rJ0GJpK8nZjkzHMztYrKYAe56pX4SvplpTyibTIiRXLyEVsmuByTHCZhO3fvGoFsav3ZuRhe9eAAWeqAh13eKDTcA0ufME3ZnmJheXEZ3OwrxnFjSf3U0clkWYVont3neh77ODKHhYnX0bOmnJJlr4RqFoLBitskY0kcGMKcZlaej21SENjDcFgaka3CfHbAH5vIFqnoX1JZrZPkQ65PZqQWImP79U3gXWKvz96lElyJZAFqn0Mbltllqw4MhlI766AvHraOmMsJoNvjv1QR7pCSnC0iX6nbqW1eVPaUSZDuZRtRIxfLA8HC9VbxufT2KZV3qG0l7wrZna5Di2MNcBE9uthuVLZcqp8vCmEhINDhRRlipR7tC2iRBHecS5WtxBCpbEm1y1kgNG5o60UKgAswxxuJ3RQ9Y49mPIApBMmp4LFpuKRfcrZb4UJnCfR3pNbQ70nnZ6Be2M7tuJUCoFfHrhqHXNz5A0uWMgxUS50c60zLl6QAELxHaCGba4WCMOHIo5nSKcUuYtDyDoDlrezALW5mZR4PRPRxnjrXxbJI14qrpymRReC3QgFDJp6sT5TLwvSHaavPlEbt2Eu0Kh5SXklGHXP9YuF3glGuJzSob3NakW1RXF5786U1MHhtJby64LyGWvNn4QXie3VjeL3QQu4C9crEAxSSiOJOfnL3DYIVOY4ipUkKFlF7Rp2q6gZazDvcUCp1cbcr7T7B4s22rXzjN7mHYWOyWuZGwlImeorY3aVKi7BaXbhgOFw6BUmIc1HeGFELHIEnPE9MwOjZam3LOm0rhBHlvJJZkXvJKmDUJrGlyqC5GtC5lDWLfXewyDWDqq7PY0atVQily5GWqib6wub6u6LZ3HZDNP8gK64Nf4kC259AE4V2hCohDnSsXAIoOkehwXyp6CkDT42NJb6sXHUv2N6cm292MiKA22PKWrwUGsan599KI2V67YRDfcfiB4ZHRDiSe62MBE0fGLIgXLIWw1xTWYbPQ9YAj3xovBvmewbJ1De4k6uS"); - b.bytes = data.len() as u64; - b.iter(|| { - let _out = keccak(&data); - }) + c.bench_function("keccak_256_with_large_input", |b| { + b.iter(|| { + let _out = keccak(black_box(&data)); + }) + }); } diff --git a/kvdb-rocksdb/Cargo.toml b/kvdb-rocksdb/Cargo.toml index 657c0392c..d7cef5999 100644 --- a/kvdb-rocksdb/Cargo.toml +++ b/kvdb-rocksdb/Cargo.toml @@ -27,6 +27,7 @@ parity-util-mem = { path = "../parity-util-mem", version = "0.4", default-featur [dev-dependencies] alloc_counter = "0.0.4" criterion = "0.3" +ethereum-types = { path = "../ethereum-types" } kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.1" } rand = "0.7.2" tempdir = "0.3.7" diff --git a/parity-crypto/benches/bench.rs b/parity-crypto/benches/bench.rs index e0830bb98..6c13aa369 100644 --- a/parity-crypto/benches/bench.rs +++ b/parity-crypto/benches/bench.rs @@ -14,11 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -#[macro_use] -extern crate criterion; - use crate::parity_crypto::publickey::Generator; -use criterion::{Bencher, Criterion}; +use criterion::{criterion_group, criterion_main, Bencher, Criterion}; criterion_group!(benches, input_len, ecdh_agree,); diff --git a/primitive-types/impls/serde/src/serialize.rs b/primitive-types/impls/serde/src/serialize.rs index 01e85c036..431a56ec7 100644 --- a/primitive-types/impls/serde/src/serialize.rs +++ b/primitive-types/impls/serde/src/serialize.rs @@ -272,9 +272,7 @@ where #[cfg(test)] mod tests { use super::*; - extern crate serde_derive; - - use self::serde_derive::{Deserialize, Serialize}; + use serde_derive::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] struct Bytes(#[serde(with = "super")] Vec); diff --git a/rlp/src/lib.rs b/rlp/src/lib.rs index ab386e689..a4c66e2ac 100644 --- a/rlp/src/lib.rs +++ b/rlp/src/lib.rs @@ -59,14 +59,10 @@ pub const EMPTY_LIST_RLP: [u8; 1] = [0xC0; 1]; /// Shortcut function to decode trusted rlp /// -/// ```rust -/// extern crate rlp; -/// -/// fn main () { -/// let data = vec![0x83, b'c', b'a', b't']; -/// let animal: String = rlp::decode(&data).expect("could not decode"); -/// assert_eq!(animal, "cat".to_owned()); -/// } +/// ``` +/// let data = vec![0x83, b'c', b'a', b't']; +/// let animal: String = rlp::decode(&data).expect("could not decode"); +/// assert_eq!(animal, "cat".to_owned()); /// ``` pub fn decode(bytes: &[u8]) -> Result where @@ -86,14 +82,10 @@ where /// Shortcut function to encode structure into rlp. /// -/// ```rust -/// extern crate rlp; -/// -/// fn main () { -/// let animal = "cat"; -/// let out = rlp::encode(&animal); -/// assert_eq!(out, vec![0x83, b'c', b'a', b't']); -/// } +/// ``` +/// let animal = "cat"; +/// let out = rlp::encode(&animal); +/// assert_eq!(out, vec![0x83, b'c', b'a', b't']); /// ``` pub fn encode(object: &E) -> Vec where diff --git a/rlp/src/stream.rs b/rlp/src/stream.rs index 6dcf1500e..851b845b9 100644 --- a/rlp/src/stream.rs +++ b/rlp/src/stream.rs @@ -53,16 +53,12 @@ impl RlpStream { /// Apends null to the end of stream, chainable. /// - /// ```rust - /// extern crate rlp; - /// use rlp::*; - /// - /// fn main () { - /// let mut stream = RlpStream::new_list(2); - /// stream.append_empty_data().append_empty_data(); - /// let out = stream.out(); - /// assert_eq!(out, vec![0xc2, 0x80, 0x80]); - /// } + /// ``` + /// use rlp::RlpStream; + /// let mut stream = RlpStream::new_list(2); + /// stream.append_empty_data().append_empty_data(); + /// let out = stream.out(); + /// assert_eq!(out, vec![0xc2, 0x80, 0x80]); /// ``` pub fn append_empty_data(&mut self) -> &mut Self { // self push raw item @@ -94,16 +90,12 @@ impl RlpStream { /// Appends value to the end of stream, chainable. /// - /// ```rust - /// extern crate rlp; - /// use rlp::*; - /// - /// fn main () { - /// let mut stream = RlpStream::new_list(2); - /// stream.append(&"cat").append(&"dog"); - /// let out = stream.out(); - /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); - /// } + /// ``` + /// use rlp::RlpStream; + /// let mut stream = RlpStream::new_list(2); + /// stream.append(&"cat").append(&"dog"); + /// let out = stream.out(); + /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); /// ``` pub fn append(&mut self, value: &E) -> &mut Self where @@ -119,16 +111,12 @@ impl RlpStream { /// Appends iterator to the end of stream, chainable. /// - /// ```rust - /// extern crate rlp; - /// use rlp::*; - /// - /// fn main () { - /// let mut stream = RlpStream::new_list(2); - /// stream.append(&"cat").append_iter("dog".as_bytes().iter().cloned()); - /// let out = stream.out(); - /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); - /// } + /// ``` + /// use rlp::RlpStream; + /// let mut stream = RlpStream::new_list(2); + /// stream.append(&"cat").append_iter("dog".as_bytes().iter().cloned()); + /// let out = stream.out(); + /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); /// ``` pub fn append_iter(&mut self, value: I) -> &mut Self where @@ -167,17 +155,13 @@ impl RlpStream { /// Declare appending the list of given size, chainable. /// - /// ```rust - /// extern crate rlp; - /// use rlp::*; - /// - /// fn main () { - /// let mut stream = RlpStream::new_list(2); - /// stream.begin_list(2).append(&"cat").append(&"dog"); - /// stream.append(&""); - /// let out = stream.out(); - /// assert_eq!(out, vec![0xca, 0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g', 0x80]); - /// } + /// ``` + /// use rlp::RlpStream; + /// let mut stream = RlpStream::new_list(2); + /// stream.begin_list(2).append(&"cat").append(&"dog"); + /// stream.append(&""); + /// let out = stream.out(); + /// assert_eq!(out, vec![0xca, 0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g', 0x80]); /// ``` pub fn begin_list(&mut self, len: usize) -> &mut RlpStream { self.finished_list = false; @@ -249,18 +233,15 @@ impl RlpStream { /// Clear the output stream so far. /// - /// ```rust - /// extern crate rlp; - /// use rlp::*; - /// - /// fn main () { - /// let mut stream = RlpStream::new_list(3); - /// stream.append(&"cat"); - /// stream.clear(); - /// stream.append(&"dog"); - /// let out = stream.out(); - /// assert_eq!(out, vec![0x83, b'd', b'o', b'g']); - /// } + /// ``` + /// use rlp::RlpStream; + /// let mut stream = RlpStream::new_list(3); + /// stream.append(&"cat"); + /// stream.clear(); + /// stream.append(&"dog"); + /// let out = stream.out(); + /// assert_eq!(out, vec![0x83, b'd', b'o', b'g']); + /// ``` pub fn clear(&mut self) { // clear bytes self.buffer.clear(); @@ -271,19 +252,16 @@ impl RlpStream { /// Returns true if stream doesnt expect any more items. /// - /// ```rust - /// extern crate rlp; - /// use rlp::*; - /// - /// fn main () { - /// let mut stream = RlpStream::new_list(2); - /// stream.append(&"cat"); - /// assert_eq!(stream.is_finished(), false); - /// stream.append(&"dog"); - /// assert_eq!(stream.is_finished(), true); - /// let out = stream.out(); - /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); - /// } + /// ``` + /// use rlp::RlpStream; + /// let mut stream = RlpStream::new_list(2); + /// stream.append(&"cat"); + /// assert_eq!(stream.is_finished(), false); + /// stream.append(&"dog"); + /// assert_eq!(stream.is_finished(), true); + /// let out = stream.out(); + /// assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']); + /// ``` pub fn is_finished(&self) -> bool { self.unfinished_lists.is_empty() } diff --git a/triehash/src/lib.rs b/triehash/src/lib.rs index 964e7e14f..81a005826 100644 --- a/triehash/src/lib.rs +++ b/triehash/src/lib.rs @@ -47,20 +47,15 @@ fn shared_prefix_len(first: &[T], second: &[T]) -> usize { /// Generates a trie root hash for a vector of values /// -/// ```rust -/// extern crate triehash; -/// extern crate keccak_hasher; -/// extern crate ethereum_types; -/// #[macro_use] extern crate hex_literal; +/// ``` +/// use hex_literal::hex; /// use ethereum_types::H256; /// use triehash::ordered_trie_root; /// use keccak_hasher::KeccakHasher; /// -/// fn main() { -/// let v = &["doe", "reindeer"]; -/// let root = H256::from(hex!("e766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3")); -/// assert_eq!(ordered_trie_root::(v), root.as_ref()); -/// } +/// let v = &["doe", "reindeer"]; +/// let root = H256::from(hex!("e766d5d51b89dc39d981b41bda63248d7abce4f0225eefd023792a540bcffee3")); +/// assert_eq!(ordered_trie_root::(v), root.as_ref()); /// ``` pub fn ordered_trie_root(input: I) -> H::Out where @@ -74,25 +69,20 @@ where /// Generates a trie root hash for a vector of key-value tuples /// -/// ```rust -/// extern crate triehash; -/// extern crate ethereum_types; -/// extern crate keccak_hasher; -/// #[macro_use] extern crate hex_literal; +/// ``` +/// use hex_literal::hex; /// use triehash::trie_root; /// use ethereum_types::H256; /// use keccak_hasher::KeccakHasher; /// -/// fn main() { -/// let v = vec![ -/// ("doe", "reindeer"), -/// ("dog", "puppy"), -/// ("dogglesworth", "cat"), -/// ]; +/// let v = vec![ +/// ("doe", "reindeer"), +/// ("dog", "puppy"), +/// ("dogglesworth", "cat"), +/// ]; /// -/// let root = H256::from(hex!("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3")); -/// assert_eq!(trie_root::(v), root.as_ref()); -/// } +/// let root = H256::from(hex!("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3")); +/// assert_eq!(trie_root::(v), root.as_ref()); /// ``` pub fn trie_root(input: I) -> H::Out where @@ -126,25 +116,20 @@ where /// Generates a key-hashed (secure) trie root hash for a vector of key-value tuples. /// -/// ```rust -/// extern crate triehash; -/// extern crate keccak_hasher; -/// extern crate ethereum_types; -/// #[macro_use] extern crate hex_literal; +/// ``` +/// use hex_literal::hex; /// use ethereum_types::H256; /// use triehash::sec_trie_root; /// use keccak_hasher::KeccakHasher; /// -/// fn main() { -/// let v = vec![ -/// ("doe", "reindeer"), -/// ("dog", "puppy"), -/// ("dogglesworth", "cat"), -/// ]; +/// let v = vec![ +/// ("doe", "reindeer"), +/// ("dog", "puppy"), +/// ("dogglesworth", "cat"), +/// ]; /// -/// let root = H256::from(hex!("d4cd937e4a4368d7931a9cf51686b7e10abb3dce38a39000fd7902a092b64585")); -/// assert_eq!(sec_trie_root::(v), root.as_ref()); -/// } +/// let root = H256::from(hex!("d4cd937e4a4368d7931a9cf51686b7e10abb3dce38a39000fd7902a092b64585")); +/// assert_eq!(sec_trie_root::(v), root.as_ref()); /// ``` pub fn sec_trie_root(input: I) -> H::Out where From a163bead36bb3003ab743742fa0d9b0698c3dada Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Wed, 15 Jan 2020 14:01:15 +0100 Subject: [PATCH 02/56] README: fix appveyor badge (#316) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b9a2936ac..b4647e7e9 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [travis-image]: https://travis-ci.org/paritytech/parity-common.svg?branch=master [travis-url]: https://travis-ci.org/paritytech/parity-common -[appveyor-image]: https://ci.appveyor.com/api/projects/status/github/paritytech/parity-common/branch/master?svg=true +[appveyor-image]: https://ci.appveyor.com/api/projects/status/github/paritytech/parity-common?branch=master&svg=true [appveyor-url]: https://ci.appveyor.com/project/paritytech/parity-common/branch/master # parity-common From 97f682ae24a6ce7c1e76ebf1c708443b47b8b7fb Mon Sep 17 00:00:00 2001 From: Artem Vorotnikov Date: Sun, 26 Jan 2020 20:33:43 +0300 Subject: [PATCH 03/56] uint: make zero const fn (#318) --- uint/src/uint.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uint/src/uint.rs b/uint/src/uint.rs index 64990bf5c..b15726b72 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -642,8 +642,8 @@ macro_rules! construct_uint { /// Zero (additive identity) of this type. #[inline] - pub fn zero() -> Self { - From::from(0u64) + pub const fn zero() -> Self { + Self([0; $n_words]) } /// One (multiplicative identity) of this type. From de318bffc7a034455bc55e9080feb095ba7326da Mon Sep 17 00:00:00 2001 From: Artem Vorotnikov Date: Mon, 27 Jan 2020 12:53:18 +0300 Subject: [PATCH 04/56] Expand const fn coverage (#319) * Expand const fn coverage * also const fn rlp * make more uint methods const fn * restore inline attribute --- fixed-hash/src/hash.rs | 10 +++++----- rlp/src/rlpin.rs | 8 ++++---- uint/src/uint.rs | 18 +++++++++--------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/fixed-hash/src/hash.rs b/fixed-hash/src/hash.rs index ea2210076..09ce43d8c 100644 --- a/fixed-hash/src/hash.rs +++ b/fixed-hash/src/hash.rs @@ -107,19 +107,19 @@ macro_rules! construct_fixed_hash { impl $name { /// Returns a new fixed hash where all bits are set to the given byte. #[inline] - pub fn repeat_byte(byte: u8) -> $name { + pub const fn repeat_byte(byte: u8) -> $name { $name([byte; $n_bytes]) } /// Returns a new zero-initialized fixed hash. #[inline] - pub fn zero() -> $name { + pub const fn zero() -> $name { $name::repeat_byte(0u8) } /// Returns the size of this hash in bytes. #[inline] - pub fn len_bytes() -> usize { + pub const fn len_bytes() -> usize { $n_bytes } @@ -137,7 +137,7 @@ macro_rules! construct_fixed_hash { /// Extracts a reference to the byte array containing the entire fixed hash. #[inline] - pub fn as_fixed_bytes(&self) -> &[u8; $n_bytes] { + pub const fn as_fixed_bytes(&self) -> &[u8; $n_bytes] { &self.0 } @@ -149,7 +149,7 @@ macro_rules! construct_fixed_hash { /// Returns the inner bytes array. #[inline] - pub fn to_fixed_bytes(self) -> [u8; $n_bytes] { + pub const fn to_fixed_bytes(self) -> [u8; $n_bytes] { self.0 } diff --git a/rlp/src/rlpin.rs b/rlp/src/rlpin.rs index f1c488626..6cdfaa808 100644 --- a/rlp/src/rlpin.rs +++ b/rlp/src/rlpin.rs @@ -25,7 +25,7 @@ struct OffsetCache { } impl OffsetCache { - fn new(index: usize, offset: usize) -> OffsetCache { + const fn new(index: usize, offset: usize) -> OffsetCache { OffsetCache { index, offset } } } @@ -68,7 +68,7 @@ fn calculate_payload_info(header_bytes: &[u8], len_of_len: usize) -> Result PayloadInfo { + const fn new(header_len: usize, value_len: usize) -> PayloadInfo { PayloadInfo { header_len, value_len } } @@ -128,7 +128,7 @@ impl<'a> fmt::Display for Rlp<'a> { } impl<'a> Rlp<'a> { - pub fn new(bytes: &'a [u8]) -> Rlp<'a> { + pub const fn new(bytes: &'a [u8]) -> Rlp<'a> { Rlp { bytes, offset_cache: Cell::new(None), count_cache: Cell::new(None) } } @@ -374,7 +374,7 @@ pub struct BasicDecoder<'a> { } impl<'a> BasicDecoder<'a> { - pub fn new(rlp: &'a [u8]) -> BasicDecoder<'a> { + pub const fn new(rlp: &'a [u8]) -> BasicDecoder<'a> { BasicDecoder { rlp } } diff --git a/uint/src/uint.rs b/uint/src/uint.rs index b15726b72..7dd1bca42 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -371,7 +371,7 @@ macro_rules! construct_uint { impl $name { /// Low 2 words (u128) #[inline] - pub fn low_u128(&self) -> u128 { + pub const fn low_u128(&self) -> u128 { let &$name(ref arr) = self; ((arr[1] as u128) << 64) + arr[0] as u128 } @@ -473,14 +473,14 @@ macro_rules! construct_uint { /// Conversion to u32 #[inline] - pub fn low_u32(&self) -> u32 { + pub const fn low_u32(&self) -> u32 { let &$name(ref arr) = self; arr[0] as u32 } /// Low word (u64) #[inline] - pub fn low_u64(&self) -> u64 { + pub const fn low_u64(&self) -> u64 { let &$name(ref arr) = self; arr[0] } @@ -560,7 +560,7 @@ macro_rules! construct_uint { /// /// Panics if `index` exceeds the bit width of the number. #[inline] - pub fn bit(&self, index: usize) -> bool { + pub const fn bit(&self, index: usize) -> bool { let &$name(ref arr) = self; arr[index / 64] & (1 << (index % 64)) != 0 } @@ -601,7 +601,7 @@ macro_rules! construct_uint { /// /// Panics if `index` exceeds the byte width of the number. #[inline] - pub fn byte(&self, index: usize) -> u8 { + pub const fn byte(&self, index: usize) -> u8 { let &$name(ref arr) = self; (arr[index / 8] >> (((index % 8)) * 8)) as u8 } @@ -1066,18 +1066,18 @@ macro_rules! construct_uint { } #[inline(always)] - fn mul_u64(a: u64, b: u64, carry: u64) -> (u64, u64) { - let (hi, lo) = Self::split_u128(u128::from(a) * u128::from(b) + u128::from(carry)); + const fn mul_u64(a: u64, b: u64, carry: u64) -> (u64, u64) { + let (hi, lo) = Self::split_u128(a as u128 * b as u128 + carry as u128); (lo, hi) } #[inline(always)] - fn split(a: u64) -> (u64, u64) { + const fn split(a: u64) -> (u64, u64) { (a >> 32, a & 0xFFFF_FFFF) } #[inline(always)] - fn split_u128(a: u128) -> (u64, u64) { + const fn split_u128(a: u128) -> (u64, u64) { ((a >> 64) as _, (a & 0xFFFFFFFFFFFFFFFF) as _) } From 97cf7820ee7297f6a19152663046fb1226b2470d Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Tue, 4 Feb 2020 11:10:36 +0100 Subject: [PATCH 05/56] travis: disable kvdb-web tests for chrome (#324) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bf3a27276..a8741dccc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,5 +54,5 @@ script: - cd parity-util-mem/ && cargo test --no-default-features --features=dlmalloc-global && cd .. - cd rlp/ && cargo test --no-default-features && cargo check --benches && cd .. - cd triehash/ && cargo check --benches && cd .. - - cd kvdb-web/ && wasm-pack test --headless --chrome --firefox && cd .. + - cd kvdb-web/ && wasm-pack test --headless --firefox && cd .. From 8440c05c286a55cc35fafa69f8decb9aca6013e1 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Tue, 4 Feb 2020 03:23:54 -0800 Subject: [PATCH 06/56] split off primitives (#323) --- parity-util-mem/Cargo.toml | 7 ++--- parity-util-mem/src/ethereum_impls.rs | 4 +-- parity-util-mem/src/lib.rs | 3 +++ parity-util-mem/src/primitives_impls.rs | 34 +++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 parity-util-mem/src/primitives_impls.rs diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index baf11981e..f38ea6ac5 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -26,6 +26,7 @@ impl-trait-for-tuples = "0.1.3" smallvec = { version = "1.0.0", optional = true } ethereum-types = { version = "0.8.0", optional = true, path = "../ethereum-types" } parking_lot = { version = "0.9.0", optional = true } +primitive-types = { version = "0.6", path = "../primitive-types", default-features = false, optional = true } [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3.8", features = ["heapapi"] } @@ -35,7 +36,7 @@ version = "0.3.2" optional = true [features] -default = ["std", "ethereum-impls", "lru", "hashbrown", "smallvec"] +default = ["std", "ethereum-impls", "lru", "hashbrown", "smallvec", "primitive-types"] std = ["parking_lot"] # use dlmalloc as global allocator dlmalloc-global = ["dlmalloc", "estimate-heapsize"] @@ -46,6 +47,6 @@ jemalloc-global = ["jemallocator"] # use mimalloc as global allocator mimalloc-global = ["mimallocator", "mimalloc-sys"] # implement additional types -ethereum-impls = ["ethereum-types"] +ethereum-impls = ["ethereum-types", "primitive-types"] # Full estimate: no call to allocator -estimate-heapsize = [] +estimate-heapsize = [] \ No newline at end of file diff --git a/parity-util-mem/src/ethereum_impls.rs b/parity-util-mem/src/ethereum_impls.rs index 243230106..4379b3b0e 100644 --- a/parity-util-mem/src/ethereum_impls.rs +++ b/parity-util-mem/src/ethereum_impls.rs @@ -17,6 +17,6 @@ //! Implementation of `MallocSize` for common ethereum types: fixed hashes //! and uints. -use ethereum_types::{Bloom, H128, H160, H256, H264, H32, H512, H520, H64, U128, U256, U512, U64}; +use ethereum_types::{Bloom, H128, H264, H32, H520, H64, U64}; -malloc_size_of_is_0!(U64, U128, U256, U512, H32, H64, H128, H160, H256, H264, H512, H520, Bloom); +malloc_size_of_is_0!(U64, H32, H64, H128, H264, H520, Bloom); diff --git a/parity-util-mem/src/lib.rs b/parity-util-mem/src/lib.rs index ddd8f1fd5..cdea52e42 100644 --- a/parity-util-mem/src/lib.rs +++ b/parity-util-mem/src/lib.rs @@ -68,6 +68,9 @@ mod malloc_size; #[cfg(feature = "ethereum-impls")] pub mod ethereum_impls; +#[cfg(feature = "primitive-types")] +pub mod primitives_impls; + pub use allocators::MallocSizeOfExt; pub use malloc_size::{MallocSizeOf, MallocSizeOfOps}; diff --git a/parity-util-mem/src/primitives_impls.rs b/parity-util-mem/src/primitives_impls.rs new file mode 100644 index 000000000..ab5953dcc --- /dev/null +++ b/parity-util-mem/src/primitives_impls.rs @@ -0,0 +1,34 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +//! Implementation of `MallocSize` primitive types. + +use primitive_types::{H160, H256, H512, U128, U256, U512}; + +malloc_size_of_is_0!(U128, U256, U512, H160, H256, H512); + +#[cfg(test)] +mod tests { + + use primitive_types::H256; + + #[test] + fn smoky() { + let v = vec![H256::zero(), H256::zero()]; + + assert!(crate::MallocSizeOfExt::malloc_size_of(&v) >= 64); + } +} From 31aed7d6bb214dace05cb18925e44990c188a768 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Tue, 4 Feb 2020 03:38:51 -0800 Subject: [PATCH 07/56] MallocSizeOf for BTreeSet (#325) * split off primitives * add for BTreeSet * Update parity-util-mem/src/malloc_size.rs Co-Authored-By: Andronik Ordian * cargo fmt Co-authored-by: Andronik Ordian --- parity-util-mem/src/malloc_size.rs | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/parity-util-mem/src/malloc_size.rs b/parity-util-mem/src/malloc_size.rs index 2f180a676..864c94abd 100644 --- a/parity-util-mem/src/malloc_size.rs +++ b/parity-util-mem/src/malloc_size.rs @@ -455,6 +455,31 @@ where } } +impl MallocShallowSizeOf for rstd::collections::BTreeSet { + fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + if ops.has_malloc_enclosing_size_of() { + // See implementation for HashSet how this works. + self.iter().next().map_or(0, |t| unsafe { ops.malloc_enclosing_size_of(t) }) + } else { + // An estimate. + self.len() * (size_of::() + size_of::()) + } + } +} + +impl MallocSizeOf for rstd::collections::BTreeSet +where + T: MallocSizeOf, +{ + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + let mut n = self.shallow_size_of(ops); + for k in self.iter() { + n += k.size_of(ops); + } + n + } +} + // PhantomData is always 0. impl MallocSizeOf for rstd::marker::PhantomData { fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { @@ -676,6 +701,7 @@ malloc_size_of_is_0!(std::time::Duration); mod tests { use crate::{allocators::new_malloc_size_ops, MallocSizeOf, MallocSizeOfOps}; use smallvec::SmallVec; + use std::collections::BTreeSet; use std::mem; impl_smallvec!(3); @@ -727,4 +753,14 @@ mod tests { let expected_min_allocs = mem::size_of::() * 4 + "ÖWL".len() + "COW".len() + "PIG".len() + "DUCK".len(); assert!(v.size_of(&mut ops) >= expected_min_allocs); } + + #[test] + fn btree_set() { + let mut set = BTreeSet::new(); + for t in 0..100 { + set.insert(vec![t]); + } + // ~36 per value + assert!(crate::malloc_size(&set) > 3000); + } } From 4986eb58f2740859a2f37589f154ab7035510105 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Tue, 4 Feb 2020 13:19:22 +0100 Subject: [PATCH 08/56] kvdb-rocksdb: fix iter_from_prefix being slow (#326) --- kvdb-rocksdb/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index d478a0c6d..40ee0f595 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -616,7 +616,7 @@ impl Database { // We're not using "Prefix Seek" mode, so the iterator will return // keys not starting with the given prefix as well, // see https://github.com/facebook/rocksdb/wiki/Prefix-Seek-API-Changes - optional.into_iter().flat_map(identity).filter(move |(k, _)| k.starts_with(prefix)) + optional.into_iter().flat_map(identity).take_while(move |(k, _)| k.starts_with(prefix)) } /// Close the database From 3377cd4a72b64987155f80f71e13a4b76e439184 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Tue, 4 Feb 2020 13:39:22 +0100 Subject: [PATCH 09/56] kvdb-rocksdb: release 0.4.2 (#327) * kvdb-rocksdb: fix iter_from_prefix being slow * kvdb-rocksdb: update the CHANGELOG * kvdb-rocksdb: bump version to 0.4.2 --- kvdb-rocksdb/CHANGELOG.md | 7 +++++++ kvdb-rocksdb/Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/kvdb-rocksdb/CHANGELOG.md b/kvdb-rocksdb/CHANGELOG.md index f2754de3b..f7cd5a5e9 100644 --- a/kvdb-rocksdb/CHANGELOG.md +++ b/kvdb-rocksdb/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.4.2] - 2019-02-04 +### Fixes +- Fixed `iter_from_prefix` being slow. [#326](https://github.com/paritytech/parity-common/pull/326) + +## [0.4.1] - 2019-01-06 +- Updated features and feature dependencies. [#307](https://github.com/paritytech/parity-common/pull/307) + ## [0.4.0] - 2019-01-03 - Add I/O statistics for RocksDB. [#294](https://github.com/paritytech/parity-common/pull/294) - Support querying memory footprint via `MallocSizeOf` trait. [#292](https://github.com/paritytech/parity-common/pull/292) diff --git a/kvdb-rocksdb/Cargo.toml b/kvdb-rocksdb/Cargo.toml index d7cef5999..797203ffe 100644 --- a/kvdb-rocksdb/Cargo.toml +++ b/kvdb-rocksdb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kvdb-rocksdb" -version = "0.4.1" +version = "0.4.2" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "kvdb implementation backed by RocksDB" From 06ae74e64aa61633a67afb5c16ed943ffd4d9542 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Tue, 4 Feb 2020 14:27:33 +0100 Subject: [PATCH 10/56] remove libc feature from fixed-hash (#317) * fixed-hash: rename impl_libc to impl_cmp * fixed-hash: add a cmp bench * fied-hash: try cmp without libc * cargo fmt * update CHANGELOGs * fixed-hash: remove unused type in the bench --- ethbloom/CHANGELOG.md | 3 +- ethbloom/Cargo.toml | 3 +- fixed-hash/CHANGELOG.md | 5 +- fixed-hash/Cargo.toml | 10 ++-- fixed-hash/benches/cmp.rs | 98 ++++++++++++++++++++++++++++++++++++ fixed-hash/src/hash.rs | 58 +-------------------- primitive-types/CHANGELOG.md | 1 + primitive-types/Cargo.toml | 1 - 8 files changed, 113 insertions(+), 66 deletions(-) create mode 100644 fixed-hash/benches/cmp.rs diff --git a/ethbloom/CHANGELOG.md b/ethbloom/CHANGELOG.md index f1da71a00..1edf138b9 100644 --- a/ethbloom/CHANGELOG.md +++ b/ethbloom/CHANGELOG.md @@ -1,10 +1,11 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) ## [0.8.1] - 2019-10-24 ### Dependencies diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 952f043c3..f9f9960fb 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -22,10 +22,9 @@ rand = "0.7.2" hex-literal = "0.2.1" [features] -default = ["std", "serialize", "libc", "rustc-hex"] +default = ["std", "serialize", "rustc-hex"] std = ["fixed-hash/std", "crunchy/std"] serialize = ["std", "impl-serde"] -libc = ["fixed-hash/libc"] rustc-hex = ["fixed-hash/rustc-hex"] [[bench]] diff --git a/fixed-hash/CHANGELOG.md b/fixed-hash/CHANGELOG.md index ae22eee7f..adf179a5e 100644 --- a/fixed-hash/CHANGELOG.md +++ b/fixed-hash/CHANGELOG.md @@ -1,14 +1,15 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) ## [0.5.2] - 2019-12-19 ### Fixed -- re-export `alloc` for both std and no-std to fix compilation (See [PR #268](https://github.com/paritytech/parity-common/pull/268)) +- re-export `alloc` for both std and no-std to fix compilation (See [PR #268](https://github.com/paritytech/parity-common/pull/268)) ## [0.5.1] - 2019-10-24 ### Dependencies diff --git a/fixed-hash/Cargo.toml b/fixed-hash/Cargo.toml index cc3d3f3a8..c12d35c57 100644 --- a/fixed-hash/Cargo.toml +++ b/fixed-hash/Cargo.toml @@ -22,12 +22,14 @@ static_assertions = "1.0.0" [dev-dependencies] rand_xorshift = "0.2.0" - -[target.'cfg(not(target_os = "unknown"))'.dependencies] -libc = { version = "0.2.65", optional = true, default-features = false } +criterion = "0.3.0" [features] -default = ["std", "libc", "rand", "rustc-hex", "byteorder"] +default = ["std", "rand", "rustc-hex", "byteorder"] std = ["rustc-hex/std", "rand/std", "byteorder/std"] api-dummy = [] # Feature used by docs.rs to display documentation of hash types + +[[bench]] +name = "cmp" +harness = false diff --git a/fixed-hash/benches/cmp.rs b/fixed-hash/benches/cmp.rs new file mode 100644 index 000000000..fd8918006 --- /dev/null +++ b/fixed-hash/benches/cmp.rs @@ -0,0 +1,98 @@ +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Benchmarks for fixed-hash cmp implementation. + +use criterion::{black_box, Criterion, ParameterizedBenchmark}; +use criterion::{criterion_group, criterion_main}; + +use fixed_hash::construct_fixed_hash; + +construct_fixed_hash! { pub struct H256(32); } + +criterion_group!(cmp, eq_equal, eq_nonequal, compare,); +criterion_main!(cmp); + +fn eq_equal(c: &mut Criterion) { + c.bench( + "eq_equal", + ParameterizedBenchmark::new( + "", + |b, x| b.iter(|| black_box(x.eq(black_box(x)))), + vec![ + H256::zero(), + H256::repeat_byte(0xAA), + H256::from([ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19, + 0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06, + ]), + H256([u8::max_value(); 32]), + ], + ), + ); +} + +fn eq_nonequal(c: &mut Criterion) { + c.bench( + "eq_nonequal", + ParameterizedBenchmark::new( + "", + |b, (x, y)| b.iter(|| black_box(x.eq(black_box(y)))), + vec![ + ( + H256::zero(), + H256::from([ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + ]), + ), + (H256::repeat_byte(0xAA), H256::repeat_byte(0xA1)), + ( + H256::from([ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19, + 0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06, + ]), + H256::from([ + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19, + 0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06, + ]), + ), + ], + ), + ); +} + +fn compare(c: &mut Criterion) { + c.bench( + "compare", + ParameterizedBenchmark::new( + "", + |b, (x, y)| b.iter(|| black_box(x.cmp(black_box(y)))), + vec![ + ( + H256::zero(), + H256::from([ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + ]), + ), + (H256::zero(), H256::zero()), + (H256::repeat_byte(0xAA), H256::repeat_byte(0xAA)), + (H256::repeat_byte(0xAA), H256::repeat_byte(0xA1)), + ( + H256::from([ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19, + 0x40, 0x84, 0xC2, 0xDF, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06, + ]), + H256::from([ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19, + 0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06, + ]), + ), + ], + ), + ); +} diff --git a/fixed-hash/src/hash.rs b/fixed-hash/src/hash.rs index 09ce43d8c..46f5c7748 100644 --- a/fixed-hash/src/hash.rs +++ b/fixed-hash/src/hash.rs @@ -313,7 +313,7 @@ macro_rules! construct_fixed_hash { impl_byteorder_for_fixed_hash!($name); impl_rand_for_fixed_hash!($name); - impl_libc_for_fixed_hash!($name); + impl_cmp_for_fixed_hash!($name); impl_rustc_hex_for_fixed_hash!($name); impl_quickcheck_for_fixed_hash!($name); } @@ -527,17 +527,9 @@ macro_rules! impl_rand_for_fixed_hash { }; } -// Implementation for disabled libc crate support. -// -// # Note -// -// Feature guarded macro definitions instead of feature guarded impl blocks -// to work around the problems of introducing `libc` crate feature in -// a user crate. -#[cfg(not(all(feature = "libc", not(target_os = "unknown"))))] #[macro_export] #[doc(hidden)] -macro_rules! impl_libc_for_fixed_hash { +macro_rules! impl_cmp_for_fixed_hash { ( $name:ident ) => { impl $crate::core_::cmp::PartialEq for $name { #[inline] @@ -555,52 +547,6 @@ macro_rules! impl_libc_for_fixed_hash { }; } -// Implementation for enabled libc crate support. -// -// # Note -// -// Feature guarded macro definitions instead of feature guarded impl blocks -// to work around the problems of introducing `libc` crate feature in -// a user crate. -#[cfg(all(feature = "libc", not(target_os = "unknown")))] -#[macro_export] -#[doc(hidden)] -macro_rules! impl_libc_for_fixed_hash { - ( $name:ident ) => { - impl $crate::core_::cmp::PartialEq for $name { - #[inline] - fn eq(&self, other: &Self) -> bool { - unsafe { - $crate::libc::memcmp( - self.as_ptr() as *const $crate::libc::c_void, - other.as_ptr() as *const $crate::libc::c_void, - Self::len_bytes(), - ) == 0 - } - } - } - - impl $crate::core_::cmp::Ord for $name { - fn cmp(&self, other: &Self) -> $crate::core_::cmp::Ordering { - let r = unsafe { - $crate::libc::memcmp( - self.as_ptr() as *const $crate::libc::c_void, - other.as_ptr() as *const $crate::libc::c_void, - Self::len_bytes(), - ) - }; - if r < 0 { - return $crate::core_::cmp::Ordering::Less; - } - if r > 0 { - return $crate::core_::cmp::Ordering::Greater; - } - $crate::core_::cmp::Ordering::Equal - } - } - }; -} - // Implementation for disabled rustc-hex crate support. // // # Note diff --git a/primitive-types/CHANGELOG.md b/primitive-types/CHANGELOG.md index 12b958c30..87ee03e6f 100644 --- a/primitive-types/CHANGELOG.md +++ b/primitive-types/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) ## [0.6.2] - 2019-01-03 - Expose to_hex and from_hex from impl-serde. [#302](https://github.com/paritytech/parity-common/pull/302) diff --git a/primitive-types/Cargo.toml b/primitive-types/Cargo.toml index 31ef6235c..3131a001f 100644 --- a/primitive-types/Cargo.toml +++ b/primitive-types/Cargo.toml @@ -18,7 +18,6 @@ impl-rlp = { version = "0.2", path = "impls/rlp", default-features = false, opti default = ["std"] std = ["uint/std", "fixed-hash/std", "impl-codec/std"] byteorder = ["fixed-hash/byteorder"] -libc = ["fixed-hash/libc"] rustc-hex = ["fixed-hash/rustc-hex"] serde = ["std", "impl-serde"] codec = ["impl-codec"] From 2f73b64efce7554b3eda682f90f68595db139d91 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Tue, 4 Feb 2020 06:05:22 -0800 Subject: [PATCH 11/56] bump parity-util-mem to 0.4.2 (#328) --- parity-util-mem/CHANGELOG.md | 4 ++++ parity-util-mem/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/parity-util-mem/CHANGELOG.md b/parity-util-mem/CHANGELOG.md index 8a24ebce3..f9c5dc482 100644 --- a/parity-util-mem/CHANGELOG.md +++ b/parity-util-mem/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.4.2] - 2020-02-04 +- Implementation of `MallocSizeOf` for BTreeSet.[#325](https://github.com/paritytech/parity-common/pull/325) +- Split off implementation of `MallocSizeOf` for primitive-types. [#323](https://github.com/paritytech/parity-common/pull/323) + ## [0.4.1] - 2020-01-06 - Implementation of `MallocSizeOf` for SmallVec no longer requires ethereum `ethereum-impls` feature. [#307](https://github.com/paritytech/parity-common/pull/307) diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index f38ea6ac5..7cabe525b 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parity-util-mem" -version = "0.4.1" +version = "0.4.2" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Collection of memory related utilities" From a8329435e19d46b3e50145a9b5a399bfac52a31f Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Tue, 4 Feb 2020 19:12:56 +0100 Subject: [PATCH 12/56] update changelogs (#329) --- kvdb-memorydb/CHANGELOG.md | 3 +++ kvdb-web/CHANGELOG.md | 8 +++++++- kvdb/CHANGELOG.md | 3 +++ parity-util-mem/CHANGELOG.md | 4 ++-- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/kvdb-memorydb/CHANGELOG.md b/kvdb-memorydb/CHANGELOG.md index a76dd644f..50bfeda77 100644 --- a/kvdb-memorydb/CHANGELOG.md +++ b/kvdb-memorydb/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.3.1] - 2019-01-06 +- Updated features and feature dependencies. [#307](https://github.com/paritytech/parity-common/pull/307) + ## [0.3.0] - 2019-01-03 - InMemory key-value database now can report memory used (via `MallocSizeOf`). [#292](https://github.com/paritytech/parity-common/pull/292) diff --git a/kvdb-web/CHANGELOG.md b/kvdb-web/CHANGELOG.md index 475d4f564..df4565ccf 100644 --- a/kvdb-web/CHANGELOG.md +++ b/kvdb-web/CHANGELOG.md @@ -1,11 +1,17 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +## [0.3.1] - 2019-01-06 +- Updated features and feature dependencies. [#307](https://github.com/paritytech/parity-common/pull/307) + +## [0.3.0] - 2019-01-04 +- Updated to new `kvdb` and `parity-util-mem` versions. [#299](https://github.com/paritytech/parity-common/pull/299) + ## [0.2.0] - 2019-12-19 ### Changed - Default column support removed from the API diff --git a/kvdb/CHANGELOG.md b/kvdb/CHANGELOG.md index f6b634d76..4fcc88e95 100644 --- a/kvdb/CHANGELOG.md +++ b/kvdb/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.3.1] - 2019-01-06 +- Updated features and feature dependencies. [#307](https://github.com/paritytech/parity-common/pull/307) + ## [0.3.0] - 2020-01-03 - I/O statistics API. [#294](https://github.com/paritytech/parity-common/pull/294) - Removed `KeyValueDBHandler` trait. [#304](https://github.com/paritytech/parity-common/pull/304) diff --git a/parity-util-mem/CHANGELOG.md b/parity-util-mem/CHANGELOG.md index f9c5dc482..595632d79 100644 --- a/parity-util-mem/CHANGELOG.md +++ b/parity-util-mem/CHANGELOG.md @@ -7,8 +7,8 @@ The format is based on [Keep a Changelog]. ## [Unreleased] ## [0.4.2] - 2020-02-04 -- Implementation of `MallocSizeOf` for BTreeSet.[#325](https://github.com/paritytech/parity-common/pull/325) -- Split off implementation of `MallocSizeOf` for primitive-types. [#323](https://github.com/paritytech/parity-common/pull/323) +- Implementation of `MallocSizeOf` for `BTreeSet`. [#325](https://github.com/paritytech/parity-common/pull/325) +- Split off implementation of `MallocSizeOf` for `primitive-types`. [#323](https://github.com/paritytech/parity-common/pull/323) ## [0.4.1] - 2020-01-06 - Implementation of `MallocSizeOf` for SmallVec no longer requires ethereum `ethereum-impls` feature. [#307](https://github.com/paritytech/parity-common/pull/307) From 996d3703489b574946ff22b513d6f15f1d747808 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 6 Feb 2020 01:15:17 -0800 Subject: [PATCH 13/56] Remove libc completely (#333) It is no longer used anywhere, right? --- fixed-hash/src/lib.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/fixed-hash/src/lib.rs b/fixed-hash/src/lib.rs index a3e7af6f7..027ba2284 100644 --- a/fixed-hash/src/lib.rs +++ b/fixed-hash/src/lib.rs @@ -18,10 +18,6 @@ pub extern crate alloc as alloc_; #[doc(hidden)] pub use core as core_; -#[cfg(all(feature = "libc", not(target_os = "unknown")))] -#[doc(hidden)] -pub use libc; - // This disables a warning for unused #[macro_use(..)] // which is incorrect since the compiler does not check // for all available configurations. @@ -38,10 +34,6 @@ pub use static_assertions::const_assert; #[doc(hidden)] pub use byteorder; -#[cfg(not(feature = "libc"))] -#[doc(hidden)] -pub mod libc {} - #[cfg(feature = "rustc-hex")] #[doc(hidden)] pub use rustc_hex; From 27e218f86a89f43ec6f6837c3235a7d75878fa57 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 6 Feb 2020 13:32:22 +0100 Subject: [PATCH 14/56] Bump parking_lot to 0.10 and minor versions (#332) * bump versions * update changelog * change bump to 0.5.0 * update deps * major bump * also kvdb-web * also shared tests to 0.2 --- kvdb-memorydb/CHANGELOG.md | 3 +++ kvdb-memorydb/Cargo.toml | 10 +++++----- kvdb-rocksdb/CHANGELOG.md | 3 +++ kvdb-rocksdb/Cargo.toml | 10 +++++----- kvdb-shared-tests/Cargo.toml | 4 ++-- kvdb-web/CHANGELOG.md | 3 +++ kvdb-web/Cargo.toml | 10 +++++----- kvdb/CHANGELOG.md | 3 +++ kvdb/Cargo.toml | 4 ++-- parity-util-mem/CHANGELOG.md | 3 +++ parity-util-mem/Cargo.toml | 4 ++-- 11 files changed, 36 insertions(+), 21 deletions(-) diff --git a/kvdb-memorydb/CHANGELOG.md b/kvdb-memorydb/CHANGELOG.md index 50bfeda77..f2f80a709 100644 --- a/kvdb-memorydb/CHANGELOG.md +++ b/kvdb-memorydb/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.4.0] - 2019-02-05 +- Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) + ## [0.3.1] - 2019-01-06 - Updated features and feature dependencies. [#307](https://github.com/paritytech/parity-common/pull/307) diff --git a/kvdb-memorydb/Cargo.toml b/kvdb-memorydb/Cargo.toml index 2ba57bbc4..954a1e117 100644 --- a/kvdb-memorydb/Cargo.toml +++ b/kvdb-memorydb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kvdb-memorydb" -version = "0.3.1" +version = "0.4.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "A key-value in-memory database that implements the `KeyValueDB` trait" @@ -8,9 +8,9 @@ license = "GPL-3.0" edition = "2018" [dependencies] -parity-util-mem = { path = "../parity-util-mem", version = "0.4", default-features = false, features = ["std"] } -parking_lot = "0.9.0" -kvdb = { version = "0.3", path = "../kvdb" } +parity-util-mem = { path = "../parity-util-mem", version = "0.5", default-features = false, features = ["std"] } +parking_lot = "0.10.0" +kvdb = { version = "0.4", path = "../kvdb" } [dev-dependencies] -kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.1" } +kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.2" } diff --git a/kvdb-rocksdb/CHANGELOG.md b/kvdb-rocksdb/CHANGELOG.md index f7cd5a5e9..10710343c 100644 --- a/kvdb-rocksdb/CHANGELOG.md +++ b/kvdb-rocksdb/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.5.0] - 2019-02-05 +- Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332 + ## [0.4.2] - 2019-02-04 ### Fixes - Fixed `iter_from_prefix` being slow. [#326](https://github.com/paritytech/parity-common/pull/326) diff --git a/kvdb-rocksdb/Cargo.toml b/kvdb-rocksdb/Cargo.toml index 797203ffe..2f67b8d99 100644 --- a/kvdb-rocksdb/Cargo.toml +++ b/kvdb-rocksdb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kvdb-rocksdb" -version = "0.4.2" +version = "0.5.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "kvdb implementation backed by RocksDB" @@ -15,19 +15,19 @@ harness = false smallvec = "1.0.0" fs-swap = "0.2.4" interleaved-ordered = "0.1.1" -kvdb = { path = "../kvdb", version = "0.3" } +kvdb = { path = "../kvdb", version = "0.4" } log = "0.4.8" num_cpus = "1.10.1" -parking_lot = "0.9.0" +parking_lot = "0.10.0" regex = "1.3.1" rocksdb = { version = "0.13", features = ["snappy"], default-features = false } owning_ref = "0.4.0" -parity-util-mem = { path = "../parity-util-mem", version = "0.4", default-features = false, features = ["std", "smallvec"] } +parity-util-mem = { path = "../parity-util-mem", version = "0.5", default-features = false, features = ["std", "smallvec"] } [dev-dependencies] alloc_counter = "0.0.4" criterion = "0.3" ethereum-types = { path = "../ethereum-types" } -kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.1" } +kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.2" } rand = "0.7.2" tempdir = "0.3.7" diff --git a/kvdb-shared-tests/Cargo.toml b/kvdb-shared-tests/Cargo.toml index 1b2158c3b..91259e851 100644 --- a/kvdb-shared-tests/Cargo.toml +++ b/kvdb-shared-tests/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "kvdb-shared-tests" -version = "0.1.0" +version = "0.2.0" authors = ["Parity Technologies "] edition = "2018" description = "Shared tests for kvdb functionality, to be executed against actual implementations" license = "GPL-3.0" [dependencies] -kvdb = { path = "../kvdb", version = "0.3" } +kvdb = { path = "../kvdb", version = "0.4" } diff --git a/kvdb-web/CHANGELOG.md b/kvdb-web/CHANGELOG.md index df4565ccf..69d10f44a 100644 --- a/kvdb-web/CHANGELOG.md +++ b/kvdb-web/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.4.0] - 2019-02-05 +- Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) + ## [0.3.1] - 2019-01-06 - Updated features and feature dependencies. [#307](https://github.com/paritytech/parity-common/pull/307) diff --git a/kvdb-web/Cargo.toml b/kvdb-web/Cargo.toml index ea77e5855..a686f6b26 100644 --- a/kvdb-web/Cargo.toml +++ b/kvdb-web/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kvdb-web" -version = "0.3.1" +version = "0.4.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "A key-value database for use in browsers" @@ -11,12 +11,12 @@ edition = "2018" [dependencies] wasm-bindgen = "0.2.54" js-sys = "0.3.31" -kvdb = { version = "0.3", path = "../kvdb" } -kvdb-memorydb = { version = "0.3", path = "../kvdb-memorydb" } +kvdb = { version = "0.4", path = "../kvdb" } +kvdb-memorydb = { version = "0.4", path = "../kvdb-memorydb" } futures = "0.3" log = "0.4.8" send_wrapper = "0.3.0" -parity-util-mem = { path = "../parity-util-mem", version = "0.4", default-features = false } +parity-util-mem = { path = "../parity-util-mem", version = "0.5", default-features = false } [dependencies.web-sys] version = "0.3.31" @@ -39,6 +39,6 @@ features = [ [dev-dependencies] console_log = "0.1.2" -kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.1" } +kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.2" } wasm-bindgen-test = "0.3.4" wasm-bindgen-futures = "0.4.4" diff --git a/kvdb/CHANGELOG.md b/kvdb/CHANGELOG.md index 4fcc88e95..e202aaa7a 100644 --- a/kvdb/CHANGELOG.md +++ b/kvdb/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.4.0] - 2019-01-06 +- Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) + ## [0.3.1] - 2019-01-06 - Updated features and feature dependencies. [#307](https://github.com/paritytech/parity-common/pull/307) diff --git a/kvdb/Cargo.toml b/kvdb/Cargo.toml index c176644ac..e6d738877 100644 --- a/kvdb/Cargo.toml +++ b/kvdb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kvdb" -version = "0.3.1" +version = "0.4.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Generic key-value trait" @@ -10,4 +10,4 @@ edition = "2018" [dependencies] smallvec = "1.0.0" bytes = { package = "parity-bytes", version = "0.1", path = "../parity-bytes" } -parity-util-mem = { path = "../parity-util-mem", version = "0.4", default-features = false } +parity-util-mem = { path = "../parity-util-mem", version = "0.5", default-features = false } diff --git a/parity-util-mem/CHANGELOG.md b/parity-util-mem/CHANGELOG.md index 595632d79..b6f2dba48 100644 --- a/parity-util-mem/CHANGELOG.md +++ b/parity-util-mem/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.5.0] - 2019-02-05 +- Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332 + ## [0.4.2] - 2020-02-04 - Implementation of `MallocSizeOf` for `BTreeSet`. [#325](https://github.com/paritytech/parity-common/pull/325) - Split off implementation of `MallocSizeOf` for `primitive-types`. [#323](https://github.com/paritytech/parity-common/pull/323) diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index 7cabe525b..02e0e222a 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parity-util-mem" -version = "0.4.2" +version = "0.5.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Collection of memory related utilities" @@ -25,7 +25,7 @@ impl-trait-for-tuples = "0.1.3" smallvec = { version = "1.0.0", optional = true } ethereum-types = { version = "0.8.0", optional = true, path = "../ethereum-types" } -parking_lot = { version = "0.9.0", optional = true } +parking_lot = { version = "0.10.0", optional = true } primitive-types = { version = "0.6", path = "../primitive-types", default-features = false, optional = true } [target.'cfg(target_os = "windows")'.dependencies] From 2c5273c2e983aa6398cd11d3af65c3d3cf7e6851 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 6 Feb 2020 15:26:54 +0100 Subject: [PATCH 15/56] [parity-crypto] Use upstream secp256k1 (#258) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use upstream secp256k1 – WIP * Use upstream 0.16 * Patch to use upstream @ 0.17 * Refactor the Generate trait * Sort out todos: we do need the context sometimes, we do use both verify and signing * Elaborate on todo * Fix vrs conversion test * Fix more tests * Fix more tests * Use new API to do what we did in C before (`ecdh_hash_function_raw()`) * Add a test for agree() to check we're agreeing with previous impl * Add todos and use new `inv_assign()` * Use wip-branch of parity fork * Sort out a few todos, add some more * Use "thin fork" of upstream secp256k1 * Relax version constraints. Something somewhere in the `eth` dependency graph requires `= 0.8.0` * Remove [patch] * Remove `inv()` from `SecretKey` * Clean up, resolve todos * Resolve todo * Apply stable rustfmt * Relax version requirements (srsly though, wtf?) * More info in the CHANGELOG --- parity-crypto/CHANGELOG.md | 6 ++ parity-crypto/Cargo.toml | 8 +- parity-crypto/src/publickey/ec_math_utils.rs | 42 ++++------ parity-crypto/src/publickey/ecdh.rs | 26 +++++-- .../src/publickey/ecdsa_signature.rs | 53 ++++++------- parity-crypto/src/publickey/ecies.rs | 4 +- parity-crypto/src/publickey/error.rs | 2 +- parity-crypto/src/publickey/extended_keys.rs | 32 ++++---- parity-crypto/src/publickey/keypair.rs | 13 ++-- .../src/publickey/keypair_generator.rs | 22 +----- parity-crypto/src/publickey/mod.rs | 13 ++-- parity-crypto/src/publickey/secret_key.rs | 76 ++++++++----------- 12 files changed, 138 insertions(+), 159 deletions(-) diff --git a/parity-crypto/CHANGELOG.md b/parity-crypto/CHANGELOG.md index 927c9dc9c..c915ee3c9 100644 --- a/parity-crypto/CHANGELOG.md +++ b/parity-crypto/CHANGELOG.md @@ -5,3 +5,9 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- Remove `inv()` from `SecretKey` (breaking) +- `Generate::generate()` does not return error +- `Secp256k1` is no longer exported +- Remove `public_is_valid()` as it is now impossible to create invalid public keys +- 0-valued `Secp::Message`s are disallowed (signatures on them are forgeable for all keys) +- updates to upstream `rust-secp256k1` at v0.17.2 diff --git a/parity-crypto/Cargo.toml b/parity-crypto/Cargo.toml index d3e7b1994..5a7ea3b9b 100644 --- a/parity-crypto/Cargo.toml +++ b/parity-crypto/Cargo.toml @@ -16,13 +16,13 @@ required-features = ["publickey"] [dependencies] tiny-keccak = { version = "2.0", features = ["keccak"] } scrypt = { version = "0.2.0", default-features = false } -parity-secp256k1 = { version = "0.7.0", optional = true } +secp256k1 = { version = "0.17.2", optional = true, features = ["recovery", "rand-std"] } ethereum-types = { version = "0.8.0", optional = true } lazy_static = { version = "1.0", optional = true } ripemd160 = "0.8.0" sha2 = "0.8.0" -digest = "0.8.1" -hmac = "0.7.1" +digest = "0.8" +hmac = "0.7" aes = "0.3.2" aes-ctr = "0.3.0" block-modes = "0.3.3" @@ -40,4 +40,4 @@ hex-literal = "0.2.1" default = [] # public key crypto utils # moved from ethkey module in parity ethereum repository -publickey = ["parity-secp256k1", "lazy_static", "ethereum-types"] +publickey = ["secp256k1", "lazy_static", "ethereum-types"] diff --git a/parity-crypto/src/publickey/ec_math_utils.rs b/parity-crypto/src/publickey/ec_math_utils.rs index 1aa55db7e..bd8653b79 100644 --- a/parity-crypto/src/publickey/ec_math_utils.rs +++ b/parity-crypto/src/publickey/ec_math_utils.rs @@ -37,25 +37,20 @@ lazy_static! { pub static ref CURVE_ORDER: U256 = H256::from_slice(&SECP256K1_CURVE_ORDER).into_uint(); } -/// Whether the public key is valid. -pub fn public_is_valid(public: &Public) -> bool { - to_secp256k1_public(public).ok().map_or(false, |p| p.is_valid()) -} - /// In-place multiply public key by secret key (EC point * scalar) pub fn public_mul_secret(public: &mut Public, secret: &Secret) -> Result<(), Error> { let key_secret = secret.to_secp256k1_secret()?; let mut key_public = to_secp256k1_public(public)?; - key_public.mul_assign(&SECP256K1, &key_secret)?; + key_public.mul_assign(&SECP256K1, &key_secret[..])?; set_public(public, &key_public); Ok(()) } /// In-place add one public key to another (EC point + EC point) pub fn public_add(public: &mut Public, other: &Public) -> Result<(), Error> { - let mut key_public = to_secp256k1_public(public)?; + let key_public = to_secp256k1_public(public)?; let other_public = to_secp256k1_public(other)?; - key_public.add_assign(&SECP256K1, &other_public)?; + let key_public = key_public.combine(&other_public)?; set_public(public, &key_public); Ok(()) } @@ -63,10 +58,10 @@ pub fn public_add(public: &mut Public, other: &Public) -> Result<(), Error> { /// In-place sub one public key from another (EC point - EC point) pub fn public_sub(public: &mut Public, other: &Public) -> Result<(), Error> { let mut key_neg_other = to_secp256k1_public(other)?; - key_neg_other.mul_assign(&SECP256K1, &key::MINUS_ONE_KEY)?; + key_neg_other.mul_assign(&SECP256K1, super::MINUS_ONE_KEY)?; let mut key_public = to_secp256k1_public(public)?; - key_public.add_assign(&SECP256K1, &key_neg_other)?; + key_public = key_public.combine(&key_neg_other)?; set_public(public, &key_public); Ok(()) } @@ -74,15 +69,14 @@ pub fn public_sub(public: &mut Public, other: &Public) -> Result<(), Error> { /// Replace a public key with its additive inverse (EC point = - EC point) pub fn public_negate(public: &mut Public) -> Result<(), Error> { let mut key_public = to_secp256k1_public(public)?; - key_public.mul_assign(&SECP256K1, &key::MINUS_ONE_KEY)?; + key_public.mul_assign(&SECP256K1, super::MINUS_ONE_KEY)?; set_public(public, &key_public); Ok(()) } /// Return the generation point (aka base point) of secp256k1 pub fn generation_point() -> Public { - let public_key = - key::PublicKey::from_slice(&SECP256K1, &BASE_POINT_BYTES).expect("constructed using constants; qed"); + let public_key = key::PublicKey::from_slice(&BASE_POINT_BYTES).expect("constructed using constants; qed"); let mut public = Public::default(); set_public(&mut public, &public_key); public @@ -95,24 +89,24 @@ fn to_secp256k1_public(public: &Public) -> Result { temp }; - Ok(key::PublicKey::from_slice(&SECP256K1, &public_data)?) + Ok(key::PublicKey::from_slice(&public_data)?) } fn set_public(public: &mut Public, key_public: &key::PublicKey) { - let key_public_serialized = key_public.serialize_vec(&SECP256K1, false); + let key_public_serialized = key_public.serialize_uncompressed(); public.as_bytes_mut().copy_from_slice(&key_public_serialized[1..65]); } #[cfg(test)] mod tests { use super::super::{Generator, Random, Secret}; - use super::{generation_point, public_add, public_is_valid, public_mul_secret, public_negate, public_sub}; + use super::{generation_point, public_add, public_mul_secret, public_negate, public_sub}; use std::str::FromStr; #[test] fn public_addition_is_commutative() { - let public1 = Random.generate().unwrap().public().clone(); - let public2 = Random.generate().unwrap().public().clone(); + let public1 = Random.generate().public().clone(); + let public2 = Random.generate().public().clone(); let mut left = public1.clone(); public_add(&mut left, &public2).unwrap(); @@ -125,8 +119,8 @@ mod tests { #[test] fn public_addition_is_reversible_with_subtraction() { - let public1 = Random.generate().unwrap().public().clone(); - let public2 = Random.generate().unwrap().public().clone(); + let public1 = Random.generate().public().clone(); + let public2 = Random.generate().public().clone(); let mut sum = public1.clone(); public_add(&mut sum, &public2).unwrap(); @@ -137,7 +131,7 @@ mod tests { #[test] fn public_negation_is_involutory() { - let public = Random.generate().unwrap().public().clone(); + let public = Random.generate().public().clone(); let mut negation = public.clone(); public_negate(&mut negation).unwrap(); public_negate(&mut negation).unwrap(); @@ -145,12 +139,6 @@ mod tests { assert_eq!(negation, public); } - #[test] - fn known_public_is_valid() { - let public = Random.generate().unwrap().public().clone(); - assert!(public_is_valid(&public)); - } - #[test] fn generation_point_expected() { let point = generation_point(); diff --git a/parity-crypto/src/publickey/ecdh.rs b/parity-crypto/src/publickey/ecdh.rs index ab22c2a09..8cdaf793a 100644 --- a/parity-crypto/src/publickey/ecdh.rs +++ b/parity-crypto/src/publickey/ecdh.rs @@ -16,21 +16,37 @@ //! ECDH key agreement scheme implemented as a free function. -use super::{Error, Public, Secret, SECP256K1}; +use super::{Error, Public, Secret}; use secp256k1::{self, ecdh, key}; /// Agree on a shared secret pub fn agree(secret: &Secret, public: &Public) -> Result { - let context = &SECP256K1; let pdata = { let mut temp = [4u8; 65]; (&mut temp[1..65]).copy_from_slice(&public[0..64]); temp }; - let publ = key::PublicKey::from_slice(context, &pdata)?; - let sec = key::SecretKey::from_slice(context, secret.as_bytes())?; - let shared = ecdh::SharedSecret::new_raw(context, &publ, &sec); + let publ = key::PublicKey::from_slice(&pdata)?; + let sec = key::SecretKey::from_slice(secret.as_bytes())?; + let shared = ecdh::SharedSecret::new_with_hash(&publ, &sec, |x, _| x.into())?; Secret::import_key(&shared[0..32]).map_err(|_| Error::Secp(secp256k1::Error::InvalidSecretKey)) } + +#[cfg(test)] +mod tests { + use super::{agree, Public, Secret}; + use std::str::FromStr; + + #[test] + fn test_agree() { + // Just some random values for secret/public to check we agree with previous implementation. + let secret = Secret::from_str("01a400760945613ff6a46383b250bf27493bfe679f05274916182776f09b28f1").unwrap(); + let public= Public::from_str("e37f3cbb0d0601dc930b8d8aa56910dd5629f2a0979cc742418960573efc5c0ff96bc87f104337d8c6ab37e597d4f9ffbd57302bc98a825519f691b378ce13f5").unwrap(); + let shared = agree(&secret, &public); + + assert!(shared.is_ok()); + assert_eq!(shared.unwrap().to_hex(), "28ab6fad6afd854ff27162e0006c3f6bd2daafc0816c85b5dfb05dbb865fa6ac",); + } +} diff --git a/parity-crypto/src/publickey/ecdsa_signature.rs b/parity-crypto/src/publickey/ecdsa_signature.rs index 6801adf10..ae245cffb 100644 --- a/parity-crypto/src/publickey/ecdsa_signature.rs +++ b/parity-crypto/src/publickey/ecdsa_signature.rs @@ -20,7 +20,10 @@ use super::{public_to_address, Address, Error, Message, Public, Secret, SECP256K use ethereum_types::{H256, H520}; use rustc_hex::{FromHex, ToHex}; use secp256k1::key::{PublicKey, SecretKey}; -use secp256k1::{Error as SecpError, Message as SecpMessage, RecoverableSignature, RecoveryId}; +use secp256k1::{ + recovery::{RecoverableSignature, RecoveryId}, + Error as SecpError, Message as SecpMessage, +}; use std::cmp::PartialEq; use std::fmt; use std::hash::{Hash, Hasher}; @@ -208,12 +211,12 @@ impl DerefMut for Signature { } /// Signs message with the given secret key. -/// Returns the corresponding signature +/// Returns the corresponding signature. pub fn sign(secret: &Secret, message: &Message) -> Result { let context = &SECP256K1; - let sec = SecretKey::from_slice(context, secret.as_ref())?; - let s = context.sign_recoverable(&SecpMessage::from_slice(&message[..])?, &sec)?; - let (rec_id, data) = s.serialize_compact(context); + let sec = SecretKey::from_slice(secret.as_ref())?; + let s = context.sign_recoverable(&SecpMessage::from_slice(&message[..])?, &sec); + let (rec_id, data) = s.serialize_compact(); let mut data_arr = [0; 65]; // no need to check if s is low, it always is @@ -225,9 +228,8 @@ pub fn sign(secret: &Secret, message: &Message) -> Result { /// Performs verification of the signature for the given message with corresponding public key pub fn verify_public(public: &Public, signature: &Signature, message: &Message) -> Result { let context = &SECP256K1; - let rsig = - RecoverableSignature::from_compact(context, &signature[0..64], RecoveryId::from_i32(signature[64] as i32)?)?; - let sig = rsig.to_standard(context); + let rsig = RecoverableSignature::from_compact(&signature[0..64], RecoveryId::from_i32(signature[64] as i32)?)?; + let sig = rsig.to_standard(); let pdata: [u8; 65] = { let mut temp = [4u8; 65]; @@ -235,7 +237,7 @@ pub fn verify_public(public: &Public, signature: &Signature, message: &Message) temp }; - let publ = PublicKey::from_slice(context, &pdata)?; + let publ = PublicKey::from_slice(&pdata)?; match context.verify(&SecpMessage::from_slice(&message[..])?, &sig, &publ) { Ok(_) => Ok(true), Err(SecpError::IncorrectSignature) => Ok(false), @@ -253,10 +255,9 @@ pub fn verify_address(address: &Address, signature: &Signature, message: &Messag /// Recovers the public key from the signature for the message pub fn recover(signature: &Signature, message: &Message) -> Result { let context = &SECP256K1; - let rsig = - RecoverableSignature::from_compact(context, &signature[0..64], RecoveryId::from_i32(signature[64] as i32)?)?; + let rsig = RecoverableSignature::from_compact(&signature[0..64], RecoveryId::from_i32(signature[64] as i32)?)?; let pubkey = context.recover(&SecpMessage::from_slice(&message[..])?, &rsig)?; - let serialized = pubkey.serialize_vec(context, false); + let serialized = pubkey.serialize_uncompressed(); let mut public = Public::default(); public.as_bytes_mut().copy_from_slice(&serialized[1..65]); @@ -272,9 +273,9 @@ mod tests { #[test] fn vrs_conversion() { // given - let keypair = Random.generate().unwrap(); - let message = Message::default(); - let signature = sign(keypair.secret(), &message).unwrap(); + let keypair = Random.generate(); + let message = Message::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(); + let signature = sign(keypair.secret(), &message).expect("can sign a non-zero message"); // when let vrs = signature.clone().into_electrum(); @@ -286,9 +287,9 @@ mod tests { #[test] fn signature_to_and_from_str() { - let keypair = Random.generate().unwrap(); - let message = Message::default(); - let signature = sign(keypair.secret(), &message).unwrap(); + let keypair = Random.generate(); + let message = Message::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(); + let signature = sign(keypair.secret(), &message).expect("can sign a non-zero message"); let string = format!("{}", signature); let deserialized = Signature::from_str(&string).unwrap(); assert_eq!(signature, deserialized); @@ -296,25 +297,25 @@ mod tests { #[test] fn sign_and_recover_public() { - let keypair = Random.generate().unwrap(); - let message = Message::default(); + let keypair = Random.generate(); + let message = Message::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(); let signature = sign(keypair.secret(), &message).unwrap(); assert_eq!(keypair.public(), &recover(&signature, &message).unwrap()); } #[test] fn sign_and_verify_public() { - let keypair = Random.generate().unwrap(); - let message = Message::default(); - let signature = sign(keypair.secret(), &message).unwrap(); + let keypair = Random.generate(); + let message = Message::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(); + let signature = sign(keypair.secret(), &message).expect("can sign a non-zero message"); assert!(verify_public(keypair.public(), &signature, &message).unwrap()); } #[test] fn sign_and_verify_address() { - let keypair = Random.generate().unwrap(); - let message = Message::default(); - let signature = sign(keypair.secret(), &message).unwrap(); + let keypair = Random.generate(); + let message = Message::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(); + let signature = sign(keypair.secret(), &message).expect("can sign a non-zero message"); assert!(verify_address(&keypair.address(), &signature, &message).unwrap()); } } diff --git a/parity-crypto/src/publickey/ecies.rs b/parity-crypto/src/publickey/ecies.rs index 7b963c138..d7c1354f3 100644 --- a/parity-crypto/src/publickey/ecies.rs +++ b/parity-crypto/src/publickey/ecies.rs @@ -27,7 +27,7 @@ const ENC_VERSION: u8 = 0x04; /// /// Authenticated data may be empty. pub fn encrypt(public: &Public, auth_data: &[u8], plain: &[u8]) -> Result, Error> { - let r = Random.generate()?; + let r = Random.generate(); let z = ecdh::agree(r.secret(), public)?; let mut key = [0u8; 32]; kdf(&z, &[0u8; 0], &mut key); @@ -122,7 +122,7 @@ mod tests { #[test] fn ecies_shared() { - let kp = Random.generate().unwrap(); + let kp = Random.generate(); let message = b"So many books, so little time"; let shared = b"shared"; diff --git a/parity-crypto/src/publickey/error.rs b/parity-crypto/src/publickey/error.rs index 322be394b..7f9bfb8e0 100644 --- a/parity-crypto/src/publickey/error.rs +++ b/parity-crypto/src/publickey/error.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -//! Module specific errors +//! Module specific errors. use crate::error::SymmError; use std::{error::Error as StdError, fmt, result}; diff --git a/parity-crypto/src/publickey/extended_keys.rs b/parity-crypto/src/publickey/extended_keys.rs index 40b33640e..44307fdf2 100644 --- a/parity-crypto/src/publickey/extended_keys.rs +++ b/parity-crypto/src/publickey/extended_keys.rs @@ -84,7 +84,7 @@ pub struct ExtendedSecret { impl ExtendedSecret { /// New extended key from given secret and chain code. pub fn with_code(secret: Secret, chain_code: H256) -> ExtendedSecret { - ExtendedSecret { secret: secret, chain_code: chain_code } + ExtendedSecret { secret, chain_code } } /// New extended key from given secret with the random chain code. @@ -93,7 +93,7 @@ impl ExtendedSecret { } /// New extended key from given secret. - /// Chain code will be derived from the secret itself (in a deterministic way). + /// Chain code will be derived from the secret itself (deterministically). pub fn new(secret: Secret) -> ExtendedSecret { let chain_code = derivation::chain_code(*secret); ExtendedSecret::with_code(secret, chain_code) @@ -263,10 +263,9 @@ mod derivation { let mut data = vec![0u8; 33 + T::len()]; let sec_private = - SecretKey::from_slice(&SECP256K1, private_key.as_bytes()).expect("Caller should provide valid private key"); - let sec_public = - PublicKey::from_secret_key(&SECP256K1, &sec_private).expect("Caller should provide valid private key"); - let public_serialized = sec_public.serialize_vec(&SECP256K1, true); + SecretKey::from_slice(private_key.as_bytes()).expect("Caller should provide valid private key"); + let sec_public = PublicKey::from_secret_key(&SECP256K1, &sec_private); + let public_serialized = sec_public.serialize(); // curve point (compressed public key) -- index // 0.33 -- 33..end @@ -319,8 +318,8 @@ mod derivation { let mut public_sec_raw = [0u8; 65]; public_sec_raw[0] = 4; public_sec_raw[1..65].copy_from_slice(public_key.as_bytes()); - let public_sec = PublicKey::from_slice(&SECP256K1, &public_sec_raw).map_err(|_| Error::InvalidPoint)?; - let public_serialized = public_sec.serialize_vec(&SECP256K1, true); + let public_sec = PublicKey::from_slice(&public_sec_raw).map_err(|_| Error::InvalidPoint)?; + let public_serialized = public_sec.serialize(); let mut data = vec![0u8; 33 + T::len()]; // curve point (compressed public key) -- index @@ -339,16 +338,15 @@ mod derivation { if *CURVE_ORDER <= new_private.into_uint() { return Err(Error::MissingIndex); } - let new_private_sec = SecretKey::from_slice(&SECP256K1, new_private.as_bytes()).expect( + let new_private_sec = SecretKey::from_slice(new_private.as_bytes()).expect( "Private key belongs to the field [0..CURVE_ORDER) (checked above); So initializing can never fail; qed", ); - let mut new_public = PublicKey::from_secret_key(&SECP256K1, &new_private_sec) - .expect("Valid private key produces valid public key"); + let mut new_public = PublicKey::from_secret_key(&SECP256K1, &new_private_sec); // Adding two points on the elliptic curves (combining two public keys) - new_public.add_assign(&SECP256K1, &public_sec).expect("Addition of two valid points produce valid point"); + new_public = new_public.combine(&public_sec).expect("Addition of two valid points produce valid point"); - let serialized = new_public.serialize_vec(&SECP256K1, false); + let serialized = new_public.serialize_uncompressed(); Ok((H512::from_slice(&serialized[1..65]), new_chain_code)) } @@ -367,9 +365,9 @@ mod derivation { } pub fn point(secret: H256) -> Result { - let sec = SecretKey::from_slice(&SECP256K1, secret.as_bytes()).map_err(|_| Error::InvalidPoint)?; - let public_sec = PublicKey::from_secret_key(&SECP256K1, &sec).map_err(|_| Error::InvalidPoint)?; - let serialized = public_sec.serialize_vec(&SECP256K1, false); + let sec = SecretKey::from_slice(secret.as_bytes()).map_err(|_| Error::InvalidPoint)?; + let public_sec = PublicKey::from_secret_key(&SECP256K1, &sec); + let serialized = public_sec.serialize_uncompressed(); Ok(H512::from_slice(&serialized[1..65])) } @@ -490,7 +488,7 @@ mod tests { } #[test] - fn match_() { + fn test_key_derivation() { let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::from_low_u64_be(1)); let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); diff --git a/parity-crypto/src/publickey/keypair.rs b/parity-crypto/src/publickey/keypair.rs index a9dc05cab..d4fa13b39 100644 --- a/parity-crypto/src/publickey/keypair.rs +++ b/parity-crypto/src/publickey/keypair.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -//! Key pair (public + secrect) description +//! Key pair (public + secret) description. use super::{Address, Error, Public, Secret, SECP256K1}; use crate::Keccak256; @@ -48,14 +48,14 @@ impl KeyPair { /// Create a pair from secret key pub fn from_secret(secret: Secret) -> Result { let context = &SECP256K1; - let s: key::SecretKey = key::SecretKey::from_slice(context, &secret[..])?; - let pub_key = key::PublicKey::from_secret_key(context, &s)?; - let serialized = pub_key.serialize_vec(context, false); + let s: key::SecretKey = key::SecretKey::from_slice(&secret[..])?; + let pub_key = key::PublicKey::from_secret_key(context, &s); + let serialized = pub_key.serialize_uncompressed(); let mut public = Public::default(); public.as_bytes_mut().copy_from_slice(&serialized[1..65]); - let keypair = KeyPair { secret: secret, public: public }; + let keypair = KeyPair { secret, public }; Ok(keypair) } @@ -67,8 +67,7 @@ impl KeyPair { /// Copies a pair from another one pub fn from_keypair(sec: key::SecretKey, publ: key::PublicKey) -> Self { - let context = &SECP256K1; - let serialized = publ.serialize_vec(context, false); + let serialized = publ.serialize_uncompressed(); let secret = Secret::from(sec); let mut public = Public::default(); public.as_bytes_mut().copy_from_slice(&serialized[1..65]); diff --git a/parity-crypto/src/publickey/keypair_generator.rs b/parity-crypto/src/publickey/keypair_generator.rs index 2ae91db6e..3afd86a97 100644 --- a/parity-crypto/src/publickey/keypair_generator.rs +++ b/parity-crypto/src/publickey/keypair_generator.rs @@ -17,29 +17,13 @@ //! Random key pair generator. Relies on the secp256k1 C-library to generate random data. use super::{Generator, KeyPair, SECP256K1}; -use rand::rngs::OsRng; -use std::convert::Infallible; /// Randomly generates new keypair, instantiating the RNG each time. pub struct Random; impl Generator for Random { - type Error = std::io::Error; - - fn generate(&mut self) -> Result { - match OsRng.generate() { - Ok(pair) => Ok(pair), - Err(void) => match void {}, // LLVM unreachable - } - } -} - -impl Generator for OsRng { - type Error = Infallible; - - fn generate(&mut self) -> Result { - let (sec, publ) = SECP256K1.generate_keypair(self).expect("context always created with full capabilities; qed"); - - Ok(KeyPair::from_keypair(sec, publ)) + fn generate(&mut self) -> KeyPair { + let (sec, publ) = SECP256K1.generate_keypair(&mut secp256k1::rand::thread_rng()); + KeyPair::from_keypair(sec, publ) } } diff --git a/parity-crypto/src/publickey/mod.rs b/parity-crypto/src/publickey/mod.rs index 12b07d176..8d487b5ad 100644 --- a/parity-crypto/src/publickey/mod.rs +++ b/parity-crypto/src/publickey/mod.rs @@ -28,7 +28,6 @@ pub mod ecdh; pub mod ecies; pub mod error; -pub use self::ec_math_utils::public_is_valid; pub use self::ecdsa_signature::{recover, sign, verify_address, verify_public, Signature}; pub use self::error::Error; pub use self::extended_keys::{Derivation, DerivationError, ExtendedKeyPair, ExtendedPublic, ExtendedSecret}; @@ -42,14 +41,18 @@ use lazy_static::lazy_static; pub use ethereum_types::{Address, Public}; pub type Message = H256; +/// The number -1 encoded as a secret key +const MINUS_ONE_KEY: &'static [u8] = &[ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, + 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x40, +]; + lazy_static! { - pub static ref SECP256K1: secp256k1::Secp256k1 = secp256k1::Secp256k1::new(); + static ref SECP256K1: secp256k1::Secp256k1 = secp256k1::Secp256k1::new(); } /// Generates new keypair. pub trait Generator { - type Error; - /// Should be called to generate new keypair. - fn generate(&mut self) -> Result; + fn generate(&mut self) -> KeyPair; } diff --git a/parity-crypto/src/publickey/secret_key.rs b/parity-crypto/src/publickey/secret_key.rs index e721ec66b..68522ca29 100644 --- a/parity-crypto/src/publickey/secret_key.rs +++ b/parity-crypto/src/publickey/secret_key.rs @@ -14,18 +14,20 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -//! Secret key implementation +//! Secret key implementation. -use super::{Error, SECP256K1}; -use ethereum_types::H256; -use secp256k1::constants::SECRET_KEY_SIZE as SECP256K1_SECRET_KEY_SIZE; -use secp256k1::key; use std::convert::TryFrom; use std::fmt; use std::ops::Deref; use std::str::FromStr; + +use ethereum_types::H256; +use secp256k1::constants::SECRET_KEY_SIZE as SECP256K1_SECRET_KEY_SIZE; +use secp256k1::key; use zeroize::Zeroize; +use crate::publickey::Error; + /// Represents secret key #[derive(Clone, PartialEq, Eq)] pub struct Secret { @@ -74,7 +76,7 @@ impl Secret { /// Imports and validates the key. pub fn import_key(key: &[u8]) -> Result { - let secret = key::SecretKey::from_slice(&super::SECP256K1, key)?; + let secret = key::SecretKey::from_slice(key)?; Ok(secret.into()) } @@ -99,7 +101,7 @@ impl Secret { (false, false) => { let mut key_secret = self.to_secp256k1_secret()?; let other_secret = other.to_secp256k1_secret()?; - key_secret.add_assign(&SECP256K1, &other_secret)?; + key_secret.add_assign(&other_secret[..])?; *self = key_secret.into(); Ok(()) @@ -118,8 +120,8 @@ impl Secret { (false, false) => { let mut key_secret = self.to_secp256k1_secret()?; let mut other_secret = other.to_secp256k1_secret()?; - other_secret.mul_assign(&SECP256K1, &key::MINUS_ONE_KEY)?; - key_secret.add_assign(&SECP256K1, &other_secret)?; + other_secret.mul_assign(super::MINUS_ONE_KEY)?; + key_secret.add_assign(&other_secret[..])?; *self = key_secret.into(); Ok(()) @@ -131,12 +133,13 @@ impl Secret { pub fn dec(&mut self) -> Result<(), Error> { match self.is_zero() { true => { - *self = key::MINUS_ONE_KEY.into(); + *self = Secret::try_from(super::MINUS_ONE_KEY) + .expect("Constructing a secret key from a known-good constant works; qed."); Ok(()) } false => { let mut key_secret = self.to_secp256k1_secret()?; - key_secret.add_assign(&SECP256K1, &key::MINUS_ONE_KEY)?; + key_secret.add_assign(super::MINUS_ONE_KEY)?; *self = key_secret.into(); Ok(()) @@ -155,7 +158,7 @@ impl Secret { (false, false) => { let mut key_secret = self.to_secp256k1_secret()?; let other_secret = other.to_secp256k1_secret()?; - key_secret.mul_assign(&SECP256K1, &other_secret)?; + key_secret.mul_assign(&other_secret[..])?; *self = key_secret.into(); Ok(()) @@ -169,7 +172,7 @@ impl Secret { true => Ok(()), false => { let mut key_secret = self.to_secp256k1_secret()?; - key_secret.mul_assign(&SECP256K1, &key::MINUS_ONE_KEY)?; + key_secret.mul_assign(super::MINUS_ONE_KEY)?; *self = key_secret.into(); Ok(()) @@ -177,15 +180,6 @@ impl Secret { } } - /// Inplace inverse secret key (1 / scalar) - pub fn inv(&mut self) -> Result<(), Error> { - let mut key_secret = self.to_secp256k1_secret()?; - key_secret.inv_assign(&SECP256K1)?; - - *self = key_secret.into(); - Ok(()) - } - /// Compute power of secret key inplace (secret ^ pow). pub fn pow(&mut self, pow: usize) -> Result<(), Error> { if self.is_zero() { @@ -206,9 +200,9 @@ impl Secret { Ok(()) } - /// Create `secp256k1::key::SecretKey` based on this secret + /// Create a `secp256k1::key::SecretKey` based on this secret. pub fn to_secp256k1_secret(&self) -> Result { - Ok(key::SecretKey::from_slice(&SECP256K1, &self[..])?) + key::SecretKey::from_slice(&self[..]).map_err(Into::into) } } @@ -239,6 +233,17 @@ impl TryFrom<&str> for Secret { } } +impl TryFrom<&[u8]> for Secret { + type Error = Error; + + fn try_from(b: &[u8]) -> Result { + if b.len() != SECP256K1_SECRET_KEY_SIZE { + return Err(Error::InvalidSecretKey); + } + Ok(Self { inner: H256::from_slice(b) }) + } +} + impl From for Secret { fn from(key: key::SecretKey) -> Self { let mut a = [0; SECP256K1_SECRET_KEY_SIZE]; @@ -261,30 +266,9 @@ mod tests { use super::Secret; use std::str::FromStr; - #[test] - fn multiplicating_secret_inversion_with_secret_gives_one() { - let secret = Random.generate().unwrap().secret().clone(); - let mut inversion = secret.clone(); - inversion.inv().unwrap(); - inversion.mul(&secret).unwrap(); - assert_eq!( - inversion, - Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap() - ); - } - - #[test] - fn secret_inversion_is_reversible_with_inversion() { - let secret = Random.generate().unwrap().secret().clone(); - let mut inversion = secret.clone(); - inversion.inv().unwrap(); - inversion.inv().unwrap(); - assert_eq!(inversion, secret); - } - #[test] fn secret_pow() { - let secret = Random.generate().unwrap().secret().clone(); + let secret = Random.generate().secret().clone(); let mut pow0 = secret.clone(); pow0.pow(0).unwrap(); From 11ad766065b8fb61e73233447f2b9a101d7ffff7 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Thu, 6 Feb 2020 22:10:40 +0100 Subject: [PATCH 16/56] Add different mode for malloc_size_of_is_0 macro dealing with generics (#334) * add another mode for malloc_size_of_is_0 macro dealing with generics * identations * add version bump and log * add doc comments * fix version --- parity-util-mem/CHANGELOG.md | 5 +- parity-util-mem/Cargo.toml | 2 +- parity-util-mem/src/malloc_size.rs | 92 +++++++++++++++++++++++------- 3 files changed, 77 insertions(+), 22 deletions(-) diff --git a/parity-util-mem/CHANGELOG.md b/parity-util-mem/CHANGELOG.md index b6f2dba48..855ea42fe 100644 --- a/parity-util-mem/CHANGELOG.md +++ b/parity-util-mem/CHANGELOG.md @@ -6,8 +6,11 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.5.1] - 2019-02-05 +- Add different mode for malloc_size_of_is_0 macro dealing with generics #334. [#332](https://github.com/paritytech/parity-common/pull/334) + ## [0.5.0] - 2019-02-05 -- Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332 +- Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) ## [0.4.2] - 2020-02-04 - Implementation of `MallocSizeOf` for `BTreeSet`. [#325](https://github.com/paritytech/parity-common/pull/325) diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index 02e0e222a..d9024ea1c 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parity-util-mem" -version = "0.5.0" +version = "0.5.1" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Collection of memory related utilities" diff --git a/parity-util-mem/src/malloc_size.rs b/parity-util-mem/src/malloc_size.rs index 864c94abd..fccdb9bcd 100644 --- a/parity-util-mem/src/malloc_size.rs +++ b/parity-util-mem/src/malloc_size.rs @@ -564,28 +564,68 @@ impl MallocSizeOf for parking_lot::RwLock { } } +/// Implement notion of 0 allocation size for some type(s). +/// +/// if used for generics, by default it will require that generaic arguments +/// should implement `MallocSizeOf`. This can be avoided with passing "any: " +/// in front of type list. +/// +/// ```rust +/// use parity_util_mem::{malloc_size, malloc_size_of_is_0}; +/// +/// struct Data

{ +/// phantom: std::marker::PhantomData

, +/// } +/// +/// malloc_size_of_is_0!(any: Data

); +/// +/// // MallocSizeOf is NOT implemented for [u8; 333] +/// assert_eq!(malloc_size(&Data::<[u8; 333]> { phantom: std::marker::PhantomData }), 0); +/// ``` +/// +/// and when no "any: " +/// +/// use parity_util_mem::{malloc_size, malloc_size_of_is_0}; +/// +/// struct Data { pub T } +/// +/// // generic argument (`T`) must be `impl MallocSizeOf` +/// malloc_size_of_is_0!(Data); +/// +/// assert_eq!(malloc_size(&Data(0u8), 0); +/// ``` #[macro_export] macro_rules! malloc_size_of_is_0( - ($($ty:ty),+) => ( - $( - impl $crate::MallocSizeOf for $ty { - #[inline(always)] - fn size_of(&self, _: &mut $crate::MallocSizeOfOps) -> usize { - 0 - } - } - )+ - ); - ($($ty:ident<$($gen:ident),+>),+) => ( - $( - impl<$($gen: $crate::MallocSizeOf),+> $crate::MallocSizeOf for $ty<$($gen),+> { - #[inline(always)] - fn size_of(&self, _: &mut $crate::MallocSizeOfOps) -> usize { - 0 - } - } - )+ - ); + ($($ty:ty),+) => ( + $( + impl $crate::MallocSizeOf for $ty { + #[inline(always)] + fn size_of(&self, _: &mut $crate::MallocSizeOfOps) -> usize { + 0 + } + } + )+ + ); + (any: $($ty:ident<$($gen:ident),+>),+) => ( + $( + impl<$($gen),+> $crate::MallocSizeOf for $ty<$($gen),+> { + #[inline(always)] + fn size_of(&self, _: &mut $crate::MallocSizeOfOps) -> usize { + 0 + } + } + )+ + ); + ($($ty:ident<$($gen:ident),+>),+) => ( + $( + impl<$($gen: $crate::MallocSizeOf),+> $crate::MallocSizeOf for $ty<$($gen),+> { + #[inline(always)] + fn size_of(&self, _: &mut $crate::MallocSizeOfOps) -> usize { + 0 + } + } + )+ + ); ); malloc_size_of_is_0!(bool, char, str); @@ -763,4 +803,16 @@ mod tests { // ~36 per value assert!(crate::malloc_size(&set) > 3000); } + + #[test] + fn special_malloc_size_of_0() { + struct Data

{ + phantom: std::marker::PhantomData

, + } + + malloc_size_of_is_0!(any: Data

); + + // MallocSizeOf is not implemented for [u8; 333] + assert_eq!(crate::malloc_size(&Data::<[u8; 333]> { phantom: std::marker::PhantomData }), 0); + } } From 4c087c0e926a5bdfc495097aa6aa1edc7bee35e4 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 7 Feb 2020 19:50:12 +0300 Subject: [PATCH 17/56] Update doc comment (#335) * Update malloc_size.rs * Update parity-util-mem/src/malloc_size.rs Co-Authored-By: Andronik Ordian * fix doc test Co-authored-by: Andronik Ordian --- parity-util-mem/src/malloc_size.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/parity-util-mem/src/malloc_size.rs b/parity-util-mem/src/malloc_size.rs index fccdb9bcd..c68f8f660 100644 --- a/parity-util-mem/src/malloc_size.rs +++ b/parity-util-mem/src/malloc_size.rs @@ -585,14 +585,15 @@ impl MallocSizeOf for parking_lot::RwLock { /// /// and when no "any: " /// +/// ```rust /// use parity_util_mem::{malloc_size, malloc_size_of_is_0}; /// -/// struct Data { pub T } +/// struct Data(pub T); /// /// // generic argument (`T`) must be `impl MallocSizeOf` /// malloc_size_of_is_0!(Data); /// -/// assert_eq!(malloc_size(&Data(0u8), 0); +/// assert_eq!(malloc_size(&Data(0u8)), 0); /// ``` #[macro_export] macro_rules! malloc_size_of_is_0( From 96c29eb185d9aa33ec0ce296192dedcadf7bdb67 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Sat, 8 Feb 2020 19:41:43 +0100 Subject: [PATCH 18/56] [parity crypto]: remove unused depend `rustc_hex` (#337) --- parity-crypto/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/parity-crypto/Cargo.toml b/parity-crypto/Cargo.toml index 5a7ea3b9b..291d29371 100644 --- a/parity-crypto/Cargo.toml +++ b/parity-crypto/Cargo.toml @@ -30,7 +30,6 @@ pbkdf2 = "0.3.0" subtle = "2.2.1" zeroize = { version = "1.0.0", default-features = false } rand = "0.7.2" -rustc-hex = "2.0" [dev-dependencies] criterion = "0.3.0" From fb349559e00fb505f7fcc0c4748ffd553102eb25 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 8 Feb 2020 21:24:22 +0100 Subject: [PATCH 19/56] [parity-crypto] prepare 0.5.0 (#336) * [parity-crypto] prepare 0.5.0 * Update parity-crypto/CHANGELOG.md Co-Authored-By: Andronik Ordian * Include https://github.com/paritytech/parity-common/pull/337 * Sort out rustc-hex * Make sure we test parity-crypto with the publockey feature enabled Co-authored-by: Andronik Ordian --- .travis.yml | 3 ++- parity-crypto/CHANGELOG.md | 15 +++++++++------ parity-crypto/Cargo.toml | 5 +++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index a8741dccc..bea20cf75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,7 +38,7 @@ script: - cargo check --all --tests - cargo check --all --benches - cargo build --all - - cargo test --all --exclude uint --exclude fixed-hash + - cargo test --all --exclude uint --exclude fixed-hash --exclude parity-crypto - if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cd contract-address/ && cargo test --features=external_doc && cd ..; fi @@ -48,6 +48,7 @@ script: - cd keccak-hash/ && cargo test --no-default-features && cd .. - cd plain_hasher/ && cargo test --no-default-features && cargo check --benches && cd .. - cd parity-bytes/ && cargo test --no-default-features && cd .. + - cd parity-crypto/ && cargo test --all-features && cd .. - cd parity-util-mem/ && cargo test --features=estimate-heapsize && cd .. - cd parity-util-mem/ && cargo test --features=jemalloc-global && cd .. - cd parity-util-mem/ && cargo test --features=mimalloc-global && cd .. diff --git a/parity-crypto/CHANGELOG.md b/parity-crypto/CHANGELOG.md index c915ee3c9..591ee42d3 100644 --- a/parity-crypto/CHANGELOG.md +++ b/parity-crypto/CHANGELOG.md @@ -5,9 +5,12 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] -- Remove `inv()` from `SecretKey` (breaking) -- `Generate::generate()` does not return error -- `Secp256k1` is no longer exported -- Remove `public_is_valid()` as it is now impossible to create invalid public keys -- 0-valued `Secp::Message`s are disallowed (signatures on them are forgeable for all keys) -- updates to upstream `rust-secp256k1` at v0.17.2 + +## [0.5.0] - 2020-02-08 +- Remove `inv()` from `SecretKey` (breaking) (https://github.com/paritytech/parity-common/pull/258) +- `Generate::generate()` does not return error (https://github.com/paritytech/parity-common/pull/258) +- `Secp256k1` is no longer exported (https://github.com/paritytech/parity-common/pull/258) +- Remove `public_is_valid()` as it is now impossible to create invalid public keys (https://github.com/paritytech/parity-common/pull/258) +- 0-valued `Secp::Message`s are disallowed (signatures on them are forgeable for all keys) (https://github.com/paritytech/parity-common/pull/258) +- Switch to upstream `rust-secp256k1` at v0.17.2 (https://github.com/paritytech/parity-common/pull/258) +- make `rustc_hex` dependency optional (https://github.com/paritytech/parity-common/pull/337) diff --git a/parity-crypto/Cargo.toml b/parity-crypto/Cargo.toml index 291d29371..aa5d7b654 100644 --- a/parity-crypto/Cargo.toml +++ b/parity-crypto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parity-crypto" -version = "0.4.2" +version = "0.5.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Crypto utils used by ethstore and network." @@ -30,6 +30,7 @@ pbkdf2 = "0.3.0" subtle = "2.2.1" zeroize = { version = "1.0.0", default-features = false } rand = "0.7.2" +rustc-hex = { version = "2.1.0", default-features = false, optional = true } [dev-dependencies] criterion = "0.3.0" @@ -39,4 +40,4 @@ hex-literal = "0.2.1" default = [] # public key crypto utils # moved from ethkey module in parity ethereum repository -publickey = ["secp256k1", "lazy_static", "ethereum-types"] +publickey = ["secp256k1", "lazy_static", "ethereum-types", "rustc-hex"] From 742827541564cd6a58bc036d7ba9cac560038c0c Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Mon, 10 Feb 2020 19:41:23 +0300 Subject: [PATCH 20/56] Disable cache if explicit memory budget=0 passed (#339) * Disable cache if exlipcit memory budget=0 passed * don't warn on block cache property anymore * remove onliner --- kvdb-rocksdb/src/lib.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index 40ee0f595..681883c01 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -236,7 +236,11 @@ impl MallocSizeOf for DBAndColumns { fn size_of(&self, ops: &mut parity_util_mem::MallocSizeOfOps) -> usize { let mut total = self.column_names.size_of(ops) // we have at least one column always, so we can call property on it - + self.static_property_or_warn(0, "rocksdb.block-cache-usage"); + + self.db + .property_int_value_cf(self.cf(0), "rocksdb.block-cache-usage") + .unwrap_or(Some(0)) + .map(|x| x as usize) + .unwrap_or(0); for v in 0..self.column_names.len() { total += self.static_property_or_warn(v, "rocksdb.estimate-table-readers-mem"); @@ -325,12 +329,16 @@ fn generate_block_based_options(config: &DatabaseConfig) -> BlockBasedOptions { // Set cache size as recommended by // https://github.com/facebook/rocksdb/wiki/Setup-Options-and-Basic-Tuning#block-cache-size let cache_size = config.memory_budget() / 3; - block_opts.set_lru_cache(cache_size); - // "index and filter blocks will be stored in block cache, together with all other data blocks." - // See: https://github.com/facebook/rocksdb/wiki/Memory-usage-in-RocksDB#indexes-and-filter-blocks - block_opts.set_cache_index_and_filter_blocks(true); - // Don't evict L0 filter/index blocks from the cache - block_opts.set_pin_l0_filter_and_index_blocks_in_cache(true); + if cache_size == 0 { + block_opts.disable_cache() + } else { + block_opts.set_lru_cache(cache_size); + // "index and filter blocks will be stored in block cache, together with all other data blocks." + // See: https://github.com/facebook/rocksdb/wiki/Memory-usage-in-RocksDB#indexes-and-filter-blocks + block_opts.set_cache_index_and_filter_blocks(true); + // Don't evict L0 filter/index blocks from the cache + block_opts.set_pin_l0_filter_and_index_blocks_in_cache(true); + } block_opts.set_bloom_filter(10, true); block_opts From fc93b7ebac72a338911c140bca5e95f7c2176bd1 Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Tue, 11 Feb 2020 17:04:33 +0100 Subject: [PATCH 21/56] Parity runtime moved to parity common for publication in crates.io (#271) * Replace `tokio_core` with `tokio` (`ring` -> 0.13) (#9657) * Replace `tokio_core` with `tokio`. * Remove `tokio-core` and replace with `tokio` in - `ethcore/stratum` - `secret_store` - `util/fetch` - `util/reactor` * Bump hyper to 0.12 in - `miner` - `util/fake-fetch` - `util/fetch` - `secret_store` * Bump `jsonrpc-***` to 0.9 in - `parity` - `ethcore/stratum` - `ipfs` - `rpc` - `rpc_client` - `whisper` * Bump `ring` to 0.13 * Use a more graceful shutdown process in `secret_store` tests. * Convert some mutexes to rwlocks in `secret_store`. * Consolidate Tokio Runtime use, remove `CpuPool`. * Rename and move the `tokio_reactor` crate (`util/reactor`) to `tokio_runtime` (`util/runtime`). * Rename `EventLoop` to `Runtime`. - Rename `EventLoop::spawn` to `Runtime::with_default_thread_count`. - Add the `Runtime::with_thread_count` method. - Rename `Remote` to `Executor`. * Remove uses of `CpuPool` and spawn all tasks via the `Runtime` executor instead. * Other changes related to `CpuPool` removal: - Remove `Reservations::with_pool`. `::new` now takes an `Executor` as an argument. - Remove `SenderReservations::with_pool`. `::new` now takes an `Executor` as an argument. * Remove secret_store runtimes. (#9888) * Remove the independent runtimes from `KeyServerHttpListener` and `KeyServerCore` and instead require a `parity_runtime::Executor` to be passed upon creation of each. * Remove the `threads` parameter from both `ClusterConfiguration` structs. * Implement the `future::Executor` trait for `parity_runtime::Executor`. * Update tests. - Update the `loop_until` function to instead use a oneshot to signal completion. - Modify the `make_key_servers` function to create and return a runtime. * misc: bump license header to 2019 (#10135) * misc: bump license header to 2019 * misc: remove_duplicate_empty_lines.sh * misc: run license header script * commit cargo lock * Upgrade to jsonrpc v14 (#11151) * Upgrade to jsonrpc v14 Contains https://github.com/paritytech/jsonrpc/pull/495 with good bugfixes to resource usage. * Bump tokio & futures. * Bump even further. * Upgrade tokio to 0.1.22 * Partially revert "Bump tokio & futures." This reverts commit 100907eb91907aa124d856d52374637256118e86. * Added README, CHANGELOG and several meta tags in Cargo.toml * Proper pr in changelog * Remove categories tag * Comments and usage fixed * Declare test usage for methods explicitly * Crate name in readme modified, complete removed * Test helpers feature added, functions marked as test only * Processed by fmt tool * Illustrative example added * Sample moved into the separate directory * use examples directory instead of custom crate * Wait till scanning completed * Timeout decreased * Unused methods removed Co-authored-by: Nick Sanders Co-authored-by: 5chdn <5chdn@users.noreply.github.com> Co-authored-by: David Co-authored-by: Nikolay Volf --- Cargo.toml | 1 + runtime/CHANGELOG.MD | 11 +++ runtime/Cargo.toml | 19 ++++ runtime/README.MD | 6 ++ runtime/examples/simple.rs | 41 ++++++++ runtime/src/lib.rs | 198 +++++++++++++++++++++++++++++++++++++ 6 files changed, 276 insertions(+) create mode 100644 runtime/CHANGELOG.MD create mode 100644 runtime/Cargo.toml create mode 100644 runtime/README.MD create mode 100644 runtime/examples/simple.rs create mode 100644 runtime/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 1ba7acb78..15633c072 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = [ "parity-path", "plain_hasher", "rlp", + "runtime", "transaction-pool", "trace-time", "triehash", diff --git a/runtime/CHANGELOG.MD b/runtime/CHANGELOG.MD new file mode 100644 index 000000000..59d2c7ffe --- /dev/null +++ b/runtime/CHANGELOG.MD @@ -0,0 +1,11 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.1.1] - 2019-11-25 +### Changed +- Moved to parity common repo, prepared for publishing (https://github.com/paritytech/parity-common/pull/271) diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml new file mode 100644 index 000000000..ca53759a0 --- /dev/null +++ b/runtime/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "parity-runtime" +version = "0.1.1" +authors = ["Parity Technologies "] +edition = "2018" + +description = "Tokio runtime wrapper" +license = "GPL-3.0" +readme = "README.md" +homepage = "https://www.parity.io/" +keywords = ["parity", "runtime", "tokio"] +include = ["Cargo.toml", "src/**/*.rs", "README.md", "CHANGELOG.md"] + +[dependencies] +futures = "0.1" +tokio = "0.1.22" + +[features] +test-helpers = [] \ No newline at end of file diff --git a/runtime/README.MD b/runtime/README.MD new file mode 100644 index 000000000..7cda2a31f --- /dev/null +++ b/runtime/README.MD @@ -0,0 +1,6 @@ +# parity-runtime + +Wrapper over tokio runtime. Provides: +- Customizable runtime with ability to spawn it in different thread models +- Corresponding runtime executor for tasks +- Runtime handle diff --git a/runtime/examples/simple.rs b/runtime/examples/simple.rs new file mode 100644 index 000000000..6448bcbf6 --- /dev/null +++ b/runtime/examples/simple.rs @@ -0,0 +1,41 @@ +// Copyright 2015-2020 Parity Technologies (UK) Ltd. +// This file is part of Parity Ethereum. + +// Parity Ethereum is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity Ethereum is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity Ethereum. If not, see . + +//! Simple example, illustating usage of runtime wrapper. + +use futures::{Future, Stream}; +use parity_runtime::Runtime; +use std::thread::park_timeout; +use std::time::Duration; +use tokio::fs::read_dir; + +/// Read current directory in a future, which is executed in the created runtime +fn main() { + let fut = read_dir(".") + .flatten_stream() + .for_each(|dir| { + println!("{:?}", dir.path()); + Ok(()) + }) + .map_err(|err| { + eprintln!("Error: {:?}", err); + () + }); + let runtime = Runtime::with_default_thread_count(); + runtime.executor().spawn(fut); + let timeout = Duration::from_secs(3); + park_timeout(timeout); +} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs new file mode 100644 index 000000000..acb1e4b6e --- /dev/null +++ b/runtime/src/lib.rs @@ -0,0 +1,198 @@ +// Copyright 2015-2020 Parity Technologies (UK) Ltd. +// This file is part of Parity Ethereum. + +// Parity Ethereum is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity Ethereum is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity Ethereum. If not, see . + +//! Tokio Runtime wrapper. + +use futures::{future, Future, IntoFuture}; +use std::sync::mpsc; +use std::{fmt, thread}; +pub use tokio::runtime::{Builder as TokioRuntimeBuilder, Runtime as TokioRuntime, TaskExecutor}; +pub use tokio::timer::Delay; + +/// Runtime for futures. +/// +/// Runs in a separate thread. +pub struct Runtime { + executor: Executor, + handle: RuntimeHandle, +} + +impl Runtime { + fn new(runtime_bldr: &mut TokioRuntimeBuilder) -> Self { + let mut runtime = runtime_bldr.build().expect( + "Building a Tokio runtime will only fail when mio components \ + cannot be initialized (catastrophic)", + ); + let (stop, stopped) = futures::oneshot(); + let (tx, rx) = mpsc::channel(); + let handle = thread::spawn(move || { + tx.send(runtime.executor()).expect("Rx is blocking upper thread."); + runtime + .block_on(futures::empty().select(stopped).map(|_| ()).map_err(|_| ())) + .expect("Tokio runtime should not have unhandled errors."); + }); + let executor = rx.recv().expect("tx is transfered to a newly spawned thread."); + + Runtime { + executor: Executor { inner: Mode::Tokio(executor) }, + handle: RuntimeHandle { close: Some(stop), handle: Some(handle) }, + } + } + + /// Spawns a new tokio runtime with a default thread count on a background + /// thread and returns a `Runtime` which can be used to spawn tasks via + /// its executor. + pub fn with_default_thread_count() -> Self { + let mut runtime_bldr = TokioRuntimeBuilder::new(); + Self::new(&mut runtime_bldr) + } + + /// Spawns a new tokio runtime with a the specified thread count on a + /// background thread and returns a `Runtime` which can be used to spawn + /// tasks via its executor. + #[cfg(any(test, feature = "test-helpers"))] + pub fn with_thread_count(thread_count: usize) -> Self { + let mut runtime_bldr = TokioRuntimeBuilder::new(); + runtime_bldr.core_threads(thread_count); + + Self::new(&mut runtime_bldr) + } + + /// Returns this runtime raw executor. + #[cfg(any(test, feature = "test-helpers"))] + pub fn raw_executor(&self) -> TaskExecutor { + if let Mode::Tokio(ref executor) = self.executor.inner { + executor.clone() + } else { + panic!("Runtime is not initialized in Tokio mode.") + } + } + + /// Returns runtime executor. + pub fn executor(&self) -> Executor { + self.executor.clone() + } +} + +#[derive(Clone)] +enum Mode { + Tokio(TaskExecutor), + // Mode used in tests + #[allow(dead_code)] + Sync, + // Mode used in tests + #[allow(dead_code)] + ThreadPerFuture, +} + +impl fmt::Debug for Mode { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + use self::Mode::*; + + match *self { + Tokio(_) => write!(fmt, "tokio"), + Sync => write!(fmt, "synchronous"), + ThreadPerFuture => write!(fmt, "thread per future"), + } + } +} + +#[derive(Debug, Clone)] +pub struct Executor { + inner: Mode, +} + +impl Executor { + /// Synchronous executor, used for tests. + #[cfg(any(test, feature = "test-helpers"))] + pub fn new_sync() -> Self { + Executor { inner: Mode::Sync } + } + + /// Spawns a new thread for each future (use only for tests). + #[cfg(any(test, feature = "test-helpers"))] + pub fn new_thread_per_future() -> Self { + Executor { inner: Mode::ThreadPerFuture } + } + + /// Spawn a future on this runtime + pub fn spawn(&self, r: R) + where + R: IntoFuture + Send + 'static, + R::Future: Send + 'static, + { + match self.inner { + Mode::Tokio(ref executor) => executor.spawn(r.into_future()), + Mode::Sync => { + let _ = r.into_future().wait(); + } + Mode::ThreadPerFuture => { + thread::spawn(move || { + let _ = r.into_future().wait(); + }); + } + } + } +} + +impl + Send + 'static> future::Executor for Executor { + fn execute(&self, future: F) -> Result<(), future::ExecuteError> { + match self.inner { + Mode::Tokio(ref executor) => executor.execute(future), + Mode::Sync => { + let _ = future.wait(); + Ok(()) + } + Mode::ThreadPerFuture => { + thread::spawn(move || { + let _ = future.wait(); + }); + Ok(()) + } + } + } +} + +/// A handle to a runtime. Dropping the handle will cause runtime to shutdown. +pub struct RuntimeHandle { + close: Option>, + handle: Option>, +} + +impl From for RuntimeHandle { + fn from(el: Runtime) -> Self { + el.handle + } +} + +impl Drop for RuntimeHandle { + fn drop(&mut self) { + self.close.take().map(|v| v.send(())); + } +} + +impl RuntimeHandle { + /// Blocks current thread and waits until the runtime is finished. + pub fn wait(mut self) -> thread::Result<()> { + self.handle.take().expect("Handle is taken only in `wait`, `wait` is consuming; qed").join() + } + + /// Finishes this runtime. + pub fn close(mut self) { + let _ = + self.close.take().expect("Close is taken only in `close` and `drop`. `close` is consuming; qed").send(()); + } +} From 5b84cd9dde1584299abbf343cb5d129615682d54 Mon Sep 17 00:00:00 2001 From: Anton Gavrilov Date: Tue, 11 Feb 2020 18:12:13 +0100 Subject: [PATCH 22/56] Format for readme and changelog corrected (#341) --- runtime/{CHANGELOG.MD => CHANGELOG.md} | 0 runtime/{README.MD => README.md} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename runtime/{CHANGELOG.MD => CHANGELOG.md} (100%) rename runtime/{README.MD => README.md} (100%) diff --git a/runtime/CHANGELOG.MD b/runtime/CHANGELOG.md similarity index 100% rename from runtime/CHANGELOG.MD rename to runtime/CHANGELOG.md diff --git a/runtime/README.MD b/runtime/README.md similarity index 100% rename from runtime/README.MD rename to runtime/README.md From 9091bf03d313b5999fb91119d7115886601f1b1a Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Wed, 12 Feb 2020 18:33:06 +0100 Subject: [PATCH 23/56] rlp-derive extracted (#343) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Move a bunch of stuff around (#10101) * Move devtools. * Merge stop_guard & rename memzero * Move price-info to miner. * Group account management * Clean up workspace members. * Move local store closer to miner. * Move clib examples. * Move registrar and hash-fetch * Move rpc_cli/rpc_client * Move stratum closer to miner. * Fix naming convention of crates. * Update Cpp examples path. * Fix paths for clib-example. * Fix removing build. * misc: bump license header to 2019 (#10135) * misc: bump license header to 2019 * misc: remove_duplicate_empty_lines.sh * misc: run license header script * commit cargo lock * Upgrade ethereum types (#10670) * cargo upgrade "ethereum-types" --all --allow-prerelease * [ethash] fix compilation errors * [ethkey] fix compilation errors * [journaldb] fix compilation errors * [dir] fix compilation errors * [ethabi] update to 0.7 * wip * [eip-712] fix compilation errors * [ethjson] fix compilation errors * [Cargo.toml] add TODO to remove patches * [ethstore] fix compilation errors * use patched keccak-hash with new primitive-types * wip * [ethcore-network-devp2p] fix compilation errors * [vm] fix compilation errors * [common-types, evm, wasm] fix compilation errors * [ethcore-db] Require AsRef instead of Deref for keys * [ethcore-blockchain] fix some compilation errors * [blooms-db] fix compilation errors Thanks a lot @dvdplm :) * we don't need no rlp ethereum feature * [ethcore] fix some compilation errors * [parity-ipfs-api] fix compilation error * [ethcore-light] fix compilation errors * [Cargo.lock] update parity-common * [ethcore-private-tx] fix some compilation errors * wip * [ethcore-private-tx] fix compilation errors * [parity-updater] fix compilation errors * [parity-rpc] fix compilation errors * [parity-bin] fix other compilation errors * update to new ethereum-types * update keccak-hash * [fastmap] fix compilation in tests * [blooms-db] fix compilation in tests * [common-types] fix compilation in tests * [triehash-ethereum] fix compilation in tests * [ethkey] fix compilation in tests * [pwasm-run-test] fix compilation errors * [wasm] fix compilation errors * [ethjson] fix compilation in tests * [eip-712] fix compilation in tests * [ethcore-blockchain] fix compilation in tests * [ethstore] fix compilation in tests * [ethstore-accounts] fix compilation in tests * [parity-hash-fetch] fix compilation in tests * [parity-whisper] fix compilation in tests * [ethcore-miner] fix compilation in tests * [ethcore-network-devp2p] fix compilation in tests * [*] upgrade rand to 0.6 * [evm] get rid of num-bigint conversions * [ethcore] downgrade trie-standardmap and criterion * [ethcore] fix some warnings * [ethcore] fix compilation in tests * [evmbin] fix compilation in tests * [updater] fix compilation in tests * [ethash] fix compilation in tests * [ethcore-secretstore] fix compilation in tests * [ethcore-sync] fix compilation in tests * [parity-rpc] fix compilation in tests * [ethcore] finally fix compilation in tests FUCK YEAH!!! * [ethstore] lazy_static is unused * [ethcore] fix test * fix up bad merge * [Cargo.toml] remove unused patches * [*] replace some git dependencies with crates.io * [Cargo.toml] remove unused lazy_static * [*] clean up * [ethcore] fix transaction_filter_deprecated test * [private-tx] fix serialization tests * fix more serialization tests * [ethkey] fix smoky test * [rpc] fix tests, please? * [ethcore] remove commented out code * Apply suggestions from code review Co-Authored-By: Tomasz Drwięga * [ethstore] remove unused dev-dependency * [ethcore] remove resolved TODO * [*] resolve keccak-hash TODO * [*] s/Address::default()/Address::zero() * [rpc] remove Subscribers::new_test * [rpc] remove EthPubSubClient::new_test * [ethcore] use trie-standardmap from crates.io * [dir] fix db_root_path * [ethcore] simplify snapshot::tests::helpers::fill_storage * Apply suggestions from code review Co-Authored-By: David * [ethcore-secretstore] resolve TODO in serialization * [ethcore-network-devp2p] resolve TODO in save_key * [Cargo.lock] update triehash * [*] use ethabi from crates.io * [ethkey] use secp256k1 from master branch * [Cargo.lock] update eth-secp256k1 * Update copyright notice 2020 (#11386) * Update copyright noticed 2020 * Update copyright in two overlooked files * rlp_derive: cleanup (#11446) * rlp_derive: update syn & co * rlp_derive: remove dummy_const * rlp_derive: remove unused attirubutes * rlp-derive: change authors * backwards compatible call_type creation_method (#11450) * rlp_derive: update syn & co * rlp_derive: remove dummy_const * rlp_derive: remove unused attirubutes * rlp-derive: change authors * rlp_derive: add rlp(default) attribute * Revert "Revert "[Trace] Distinguish between `create` and `create2` (#11311)" (#11427)" This reverts commit 5d4993b0f856bf9e0e2c78849b72e581f0cde686. * trace: backwards compatible call_type and creation_method * trace: add rlp backward compatibility tests * cleanup * i know, i hate backwards compatibility too * address review grumbles * rlp-derive: change license and add a changelog * rlp-derive: tests license header as well * add rlp-derive to workspace * rename to rlp-derive * remove unnecessary line * rlp-derive: more module docs * cargo fmt * trigger the ci * Revert "trigger the ci" This reverts commit 5f21a4f30f38996eaadec68d0accc67f9122a6ad. Co-authored-by: Tomasz Drwięga Co-authored-by: 5chdn <5chdn@users.noreply.github.com> Co-authored-by: s3krit --- Cargo.toml | 1 + rlp-derive/CHANGELOG.md | 10 +++ rlp-derive/Cargo.toml | 19 +++++ rlp-derive/src/de.rs | 163 ++++++++++++++++++++++++++++++++++++++++ rlp-derive/src/en.rs | 109 +++++++++++++++++++++++++++ rlp-derive/src/lib.rs | 54 +++++++++++++ rlp-derive/tests/rlp.rs | 71 +++++++++++++++++ 7 files changed, 427 insertions(+) create mode 100644 rlp-derive/CHANGELOG.md create mode 100644 rlp-derive/Cargo.toml create mode 100644 rlp-derive/src/de.rs create mode 100644 rlp-derive/src/en.rs create mode 100644 rlp-derive/src/lib.rs create mode 100644 rlp-derive/tests/rlp.rs diff --git a/Cargo.toml b/Cargo.toml index 15633c072..019b989de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = [ "parity-path", "plain_hasher", "rlp", + "rlp-derive", "runtime", "transaction-pool", "trace-time", diff --git a/rlp-derive/CHANGELOG.md b/rlp-derive/CHANGELOG.md new file mode 100644 index 000000000..592d3fbf9 --- /dev/null +++ b/rlp-derive/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] + +## [0.1.0] - 2020-02-12 +- Extracted from parity-ethereum repo. [#343](https://github.com/paritytech/parity-common/pull/343) diff --git a/rlp-derive/Cargo.toml b/rlp-derive/Cargo.toml new file mode 100644 index 000000000..bf4d0eaf0 --- /dev/null +++ b/rlp-derive/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "rlp-derive" +version = "0.1.0" +authors = ["Parity Technologies "] +license = "MIT/Apache-2.0" +description = "Derive macro for #[derive(RlpEncodable, RlpDecodable)]" +homepage = "http://parity.io" +edition = "2018" + +[lib] +proc-macro = true + +[dependencies] +syn = "1.0.14" +quote = "1.0.2" +proc-macro2 = "1.0.8" + +[dev-dependencies] +rlp = "0.4.0" diff --git a/rlp-derive/src/de.rs b/rlp-derive/src/de.rs new file mode 100644 index 000000000..d1b4e4ca5 --- /dev/null +++ b/rlp-derive/src/de.rs @@ -0,0 +1,163 @@ +// Copyright 2015-2020 Parity Technologies (UK) Ltd. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use proc_macro2::TokenStream; +use quote::quote; + +struct ParseQuotes { + single: TokenStream, + list: TokenStream, + takes_index: bool, +} + +fn decodable_parse_quotes() -> ParseQuotes { + ParseQuotes { single: quote! { rlp.val_at }, list: quote! { rlp.list_at }, takes_index: true } +} + +fn decodable_wrapper_parse_quotes() -> ParseQuotes { + ParseQuotes { single: quote! { rlp.as_val }, list: quote! { rlp.as_list }, takes_index: false } +} + +pub fn impl_decodable(ast: &syn::DeriveInput) -> TokenStream { + let body = match ast.data { + syn::Data::Struct(ref s) => s, + _ => panic!("#[derive(RlpDecodable)] is only defined for structs."), + }; + + let mut default_attribute_encountered = false; + let stmts: Vec<_> = body + .fields + .iter() + .enumerate() + .map(|(i, field)| decodable_field(i, field, decodable_parse_quotes(), &mut default_attribute_encountered)) + .collect(); + let name = &ast.ident; + + let impl_block = quote! { + impl rlp::Decodable for #name { + fn decode(rlp: &rlp::Rlp) -> Result { + let result = #name { + #(#stmts)* + }; + + Ok(result) + } + } + }; + + quote! { + const _: () = { + extern crate rlp; + #impl_block + }; + } +} + +pub fn impl_decodable_wrapper(ast: &syn::DeriveInput) -> TokenStream { + let body = match ast.data { + syn::Data::Struct(ref s) => s, + _ => panic!("#[derive(RlpDecodableWrapper)] is only defined for structs."), + }; + + let stmt = { + let fields: Vec<_> = body.fields.iter().collect(); + if fields.len() == 1 { + let field = fields.first().expect("fields.len() == 1; qed"); + let mut default_attribute_encountered = false; + decodable_field(0, field, decodable_wrapper_parse_quotes(), &mut default_attribute_encountered) + } else { + panic!("#[derive(RlpEncodableWrapper)] is only defined for structs with one field.") + } + }; + + let name = &ast.ident; + + let impl_block = quote! { + impl rlp::Decodable for #name { + fn decode(rlp: &rlp::Rlp) -> Result { + let result = #name { + #stmt + }; + + Ok(result) + } + } + }; + + quote! { + const _: () = { + extern crate rlp; + #impl_block + }; + } +} + +fn decodable_field( + index: usize, + field: &syn::Field, + quotes: ParseQuotes, + default_attribute_encountered: &mut bool, +) -> TokenStream { + let id = match field.ident { + Some(ref ident) => quote! { #ident }, + None => { + let index: syn::Index = index.into(); + quote! { #index } + } + }; + + let index = index - *default_attribute_encountered as usize; + let index = quote! { #index }; + + let single = quotes.single; + let list = quotes.list; + + let attributes = &field.attrs; + let default = if let Some(attr) = attributes.iter().find(|attr| attr.path.is_ident("rlp")) { + if *default_attribute_encountered { + panic!("only 1 #[rlp(default)] attribute is allowed in a struct") + } + match attr.parse_args() { + Ok(proc_macro2::TokenTree::Ident(ident)) if ident.to_string() == "default" => {} + _ => panic!("only #[rlp(default)] attribute is supported"), + } + *default_attribute_encountered = true; + true + } else { + false + }; + + match field.ty { + syn::Type::Path(ref path) => { + let ident = &path.path.segments.first().expect("there must be at least 1 segment").ident; + let ident_type = ident.to_string(); + if &ident_type == "Vec" { + if quotes.takes_index { + if default { + quote! { #id: #list(#index).unwrap_or_default(), } + } else { + quote! { #id: #list(#index)?, } + } + } else { + quote! { #id: #list()?, } + } + } else { + if quotes.takes_index { + if default { + quote! { #id: #single(#index).unwrap_or_default(), } + } else { + quote! { #id: #single(#index)?, } + } + } else { + quote! { #id: #single()?, } + } + } + } + _ => panic!("rlp_derive not supported"), + } +} diff --git a/rlp-derive/src/en.rs b/rlp-derive/src/en.rs new file mode 100644 index 000000000..9eb0d6afb --- /dev/null +++ b/rlp-derive/src/en.rs @@ -0,0 +1,109 @@ +// Copyright 2015-2020 Parity Technologies (UK) Ltd. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use proc_macro2::TokenStream; +use quote::quote; + +pub fn impl_encodable(ast: &syn::DeriveInput) -> TokenStream { + let body = match ast.data { + syn::Data::Struct(ref s) => s, + _ => panic!("#[derive(RlpEncodable)] is only defined for structs."), + }; + + let stmts: Vec<_> = body.fields.iter().enumerate().map(|(i, field)| encodable_field(i, field)).collect(); + let name = &ast.ident; + + let stmts_len = stmts.len(); + let stmts_len = quote! { #stmts_len }; + let impl_block = quote! { + impl rlp::Encodable for #name { + fn rlp_append(&self, stream: &mut rlp::RlpStream) { + stream.begin_list(#stmts_len); + #(#stmts)* + } + } + }; + + quote! { + const _: () = { + extern crate rlp; + #impl_block + }; + } +} + +pub fn impl_encodable_wrapper(ast: &syn::DeriveInput) -> TokenStream { + let body = match ast.data { + syn::Data::Struct(ref s) => s, + _ => panic!("#[derive(RlpEncodableWrapper)] is only defined for structs."), + }; + + let stmt = { + let fields: Vec<_> = body.fields.iter().collect(); + if fields.len() == 1 { + let field = fields.first().expect("fields.len() == 1; qed"); + encodable_field(0, field) + } else { + panic!("#[derive(RlpEncodableWrapper)] is only defined for structs with one field.") + } + }; + + let name = &ast.ident; + + let impl_block = quote! { + impl rlp::Encodable for #name { + fn rlp_append(&self, stream: &mut rlp::RlpStream) { + #stmt + } + } + }; + + quote! { + const _: () = { + extern crate rlp; + #impl_block + }; + } +} + +fn encodable_field(index: usize, field: &syn::Field) -> TokenStream { + let ident = match field.ident { + Some(ref ident) => quote! { #ident }, + None => { + let index: syn::Index = index.into(); + quote! { #index } + } + }; + + let id = quote! { self.#ident }; + + match field.ty { + syn::Type::Path(ref path) => { + let top_segment = path.path.segments.first().expect("there must be at least 1 segment"); + let ident = &top_segment.ident; + if &ident.to_string() == "Vec" { + let inner_ident = match top_segment.arguments { + syn::PathArguments::AngleBracketed(ref angle) => { + let ty = angle.args.first().expect("Vec has only one angle bracketed type; qed"); + match *ty { + syn::GenericArgument::Type(syn::Type::Path(ref path)) => { + &path.path.segments.first().expect("there must be at least 1 segment").ident + } + _ => panic!("rlp_derive not supported"), + } + } + _ => unreachable!("Vec has only one angle bracketed type; qed"), + }; + quote! { stream.append_list::<#inner_ident, _>(&#id); } + } else { + quote! { stream.append(&#id); } + } + } + _ => panic!("rlp_derive not supported"), + } +} diff --git a/rlp-derive/src/lib.rs b/rlp-derive/src/lib.rs new file mode 100644 index 000000000..47efd2ffe --- /dev/null +++ b/rlp-derive/src/lib.rs @@ -0,0 +1,54 @@ +// Copyright 2015-2020 Parity Technologies (UK) Ltd. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Derive macro for `#[derive(RlpEncodable, RlpDecodable)]`. +//! +//! For example of usage see `./tests/rlp.rs`. +//! +//! This library also supports up to 1 `#[rlp(default)]` in a struct, +//! which is similar to [`#[serde(default)]`](https://serde.rs/field-attrs.html#default) +//! with the caveat that we use the `Default` value if +//! the field deserialization fails, as we don't serialize field +//! names and there is no way to tell if it is present or not. + +extern crate proc_macro; + +mod de; +mod en; + +use de::{impl_decodable, impl_decodable_wrapper}; +use en::{impl_encodable, impl_encodable_wrapper}; +use proc_macro::TokenStream; + +#[proc_macro_derive(RlpEncodable, attributes(rlp))] +pub fn encodable(input: TokenStream) -> TokenStream { + let ast = syn::parse(input).unwrap(); + let gen = impl_encodable(&ast); + gen.into() +} + +#[proc_macro_derive(RlpEncodableWrapper)] +pub fn encodable_wrapper(input: TokenStream) -> TokenStream { + let ast = syn::parse(input).unwrap(); + let gen = impl_encodable_wrapper(&ast); + gen.into() +} + +#[proc_macro_derive(RlpDecodable, attributes(rlp))] +pub fn decodable(input: TokenStream) -> TokenStream { + let ast = syn::parse(input).unwrap(); + let gen = impl_decodable(&ast); + gen.into() +} + +#[proc_macro_derive(RlpDecodableWrapper)] +pub fn decodable_wrapper(input: TokenStream) -> TokenStream { + let ast = syn::parse(input).unwrap(); + let gen = impl_decodable_wrapper(&ast); + gen.into() +} diff --git a/rlp-derive/tests/rlp.rs b/rlp-derive/tests/rlp.rs new file mode 100644 index 000000000..e3cda4dbc --- /dev/null +++ b/rlp-derive/tests/rlp.rs @@ -0,0 +1,71 @@ +// Copyright 2015-2020 Parity Technologies (UK) Ltd. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use rlp::{decode, encode}; +use rlp_derive::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; + +#[derive(Debug, PartialEq, RlpEncodable, RlpDecodable)] +struct Foo { + a: String, +} + +#[derive(Debug, PartialEq, RlpEncodableWrapper, RlpDecodableWrapper)] +struct FooWrapper { + a: String, +} + +#[test] +fn test_encode_foo() { + let foo = Foo { a: "cat".into() }; + + let expected = vec![0xc4, 0x83, b'c', b'a', b't']; + let out = encode(&foo); + assert_eq!(out, expected); + + let decoded = decode(&expected).expect("decode failure"); + assert_eq!(foo, decoded); +} + +#[test] +fn test_encode_foo_wrapper() { + let foo = FooWrapper { a: "cat".into() }; + + let expected = vec![0x83, b'c', b'a', b't']; + let out = encode(&foo); + assert_eq!(out, expected); + + let decoded = decode(&expected).expect("decode failure"); + assert_eq!(foo, decoded); +} + +#[test] +fn test_encode_foo_default() { + #[derive(Debug, PartialEq, RlpEncodable, RlpDecodable)] + struct FooDefault { + a: String, + /// It works with other attributes. + #[rlp(default)] + b: Option>, + } + + let attack_of = String::from("clones"); + let foo = Foo { a: attack_of.clone() }; + + let expected = vec![0xc7, 0x86, b'c', b'l', b'o', b'n', b'e', b's']; + let out = encode(&foo); + assert_eq!(out, expected); + + let foo_default = FooDefault { a: attack_of.clone(), b: None }; + + let decoded = decode(&expected).expect("default failure"); + assert_eq!(foo_default, decoded); + + let foo_some = FooDefault { a: attack_of.clone(), b: Some(vec![1, 2, 3]) }; + let out = encode(&foo_some); + assert_eq!(decode(&out), Ok(foo_some)); +} From 46d8f6b5419edea4c7b2d46a09ecf3bee3facc7b Mon Sep 17 00:00:00 2001 From: David Date: Wed, 12 Feb 2020 23:31:29 +0100 Subject: [PATCH 24/56] Update/change licenses: MIT/Apache2.0 (#342) * Change license for all GPL crates to dual MIT/Apache2.0 license Change license for all MIT crates to dual MIT/Apache2.0 license Normalize "license" key in all Cargo.tomls: MIT/Apache2.0 Add MIT and Apache2.0 licenses to the repo root * License headers * Single year is enough * Add note to changelog * Review grumbles. * typo --- LICENSE | 674 ------------------ rlp/LICENSE-APACHE2 => LICENSE-APACHE2 | 0 rlp/LICENSE-MIT => LICENSE-MIT | 2 +- contract-address/CHANGELOG.md | 1 + contract-address/Cargo.toml | 2 +- contract-address/src/lib.rs | 22 +- ethbloom/CHANGELOG.md | 1 + ethbloom/Cargo.toml | 2 +- ethbloom/benches/bloom.rs | 8 + ethbloom/benches/unrolling.rs | 8 + ethbloom/src/lib.rs | 8 + ethereum-types/CHANGELOG.md | 2 + ethereum-types/Cargo.toml | 2 +- ethereum-types/src/hash.rs | 8 + ethereum-types/src/lib.rs | 8 + ethereum-types/src/uint.rs | 8 + ethereum-types/tests/serde.rs | 2 +- fixed-hash/CHANGELOG.md | 1 + fixed-hash/Cargo.toml | 2 +- fixed-hash/src/hash.rs | 2 +- fixed-hash/src/lib.rs | 2 +- fixed-hash/src/tests.rs | 8 + keccak-hash/CHANGELOG.md | 1 + keccak-hash/Cargo.toml | 2 +- keccak-hash/benches/keccak_256.rs | 22 +- keccak-hash/src/lib.rs | 22 +- kvdb-memorydb/CHANGELOG.md | 1 + kvdb-memorydb/Cargo.toml | 2 +- kvdb-memorydb/src/lib.rs | 22 +- kvdb-rocksdb/CHANGELOG.md | 1 + kvdb-rocksdb/Cargo.toml | 2 +- kvdb-rocksdb/benches/bench_read_perf.rs | 22 +- kvdb-rocksdb/src/iter.rs | 22 +- kvdb-rocksdb/src/lib.rs | 22 +- kvdb-rocksdb/src/stats.rs | 22 +- kvdb-shared-tests/Cargo.toml | 2 +- kvdb-shared-tests/src/lib.rs | 22 +- kvdb-web/CHANGELOG.md | 1 + kvdb-web/Cargo.toml | 2 +- kvdb-web/src/error.rs | 22 +- kvdb-web/src/indexed_db.rs | 22 +- kvdb-web/src/lib.rs | 22 +- kvdb-web/tests/indexed_db.rs | 22 +- kvdb/CHANGELOG.md | 1 + kvdb/Cargo.toml | 2 +- kvdb/src/io_stats.rs | 22 +- kvdb/src/lib.rs | 22 +- rlp/license-header => license-header | 2 +- parity-bytes/CHANGELOG.md | 1 + parity-bytes/Cargo.toml | 2 +- parity-bytes/src/lib.rs | 22 +- parity-crypto/CHANGELOG.md | 1 + parity-crypto/Cargo.toml | 2 +- parity-crypto/benches/bench.rs | 22 +- parity-crypto/src/aes.rs | 22 +- parity-crypto/src/digest.rs | 22 +- parity-crypto/src/error.rs | 22 +- parity-crypto/src/hmac/mod.rs | 22 +- parity-crypto/src/hmac/test.rs | 22 +- parity-crypto/src/lib.rs | 22 +- parity-crypto/src/pbkdf2/mod.rs | 22 +- parity-crypto/src/pbkdf2/test.rs | 22 +- parity-crypto/src/publickey/ec_math_utils.rs | 22 +- parity-crypto/src/publickey/ecdh.rs | 22 +- .../src/publickey/ecdsa_signature.rs | 22 +- parity-crypto/src/publickey/ecies.rs | 22 +- parity-crypto/src/publickey/error.rs | 22 +- parity-crypto/src/publickey/extended_keys.rs | 22 +- parity-crypto/src/publickey/keypair.rs | 22 +- .../src/publickey/keypair_generator.rs | 22 +- parity-crypto/src/publickey/mod.rs | 22 +- parity-crypto/src/publickey/secret_key.rs | 22 +- parity-crypto/src/scrypt.rs | 22 +- parity-path/CHANGELOG.md | 1 + parity-path/Cargo.toml | 2 +- parity-path/src/lib.rs | 22 +- parity-util-mem/CHANGELOG.md | 1 + parity-util-mem/Cargo.toml | 4 +- parity-util-mem/derive/Cargo.toml | 2 +- parity-util-mem/derive/lib.rs | 22 +- parity-util-mem/src/allocators.rs | 22 +- parity-util-mem/src/ethereum_impls.rs | 22 +- parity-util-mem/src/lib.rs | 22 +- parity-util-mem/src/primitives_impls.rs | 22 +- parity-util-mem/src/sizeof.rs | 22 +- parity-util-mem/tests/derive.rs | 22 +- plain_hasher/CHANGELOG.md | 1 + plain_hasher/Cargo.toml | 2 +- plain_hasher/benches/bench.rs | 22 +- plain_hasher/src/lib.rs | 22 +- primitive-types/Cargo.toml | 2 +- primitive-types/impls/codec/Cargo.toml | 2 +- primitive-types/impls/codec/src/lib.rs | 2 +- primitive-types/impls/rlp/Cargo.toml | 2 +- primitive-types/impls/rlp/src/lib.rs | 2 +- primitive-types/impls/serde/Cargo.toml | 2 +- .../impls/serde/benches/impl_serde.rs | 2 +- primitive-types/impls/serde/benches/input.rs | 8 + primitive-types/impls/serde/src/lib.rs | 2 +- primitive-types/impls/serde/src/serialize.rs | 2 +- primitive-types/src/lib.rs | 2 +- rlp/benches/rlp.rs | 2 +- rlp/src/error.rs | 2 +- rlp/src/impls.rs | 2 +- rlp/src/lib.rs | 2 +- rlp/src/rlpin.rs | 2 +- rlp/src/stream.rs | 2 +- rlp/src/traits.rs | 2 +- rlp/tests/tests.rs | 2 +- trace-time/CHANGELOG.md | 1 + trace-time/Cargo.toml | 2 +- trace-time/src/lib.rs | 22 +- transaction-pool/CHANGELOG.md | 1 + transaction-pool/Cargo.toml | 2 +- transaction-pool/src/error.rs | 22 +- transaction-pool/src/lib.rs | 22 +- transaction-pool/src/listener.rs | 22 +- transaction-pool/src/options.rs | 22 +- transaction-pool/src/pool.rs | 22 +- transaction-pool/src/ready.rs | 22 +- transaction-pool/src/replace.rs | 22 +- transaction-pool/src/scoring.rs | 22 +- transaction-pool/src/status.rs | 22 +- transaction-pool/src/tests/helpers.rs | 22 +- transaction-pool/src/tests/mod.rs | 22 +- transaction-pool/src/tests/tx_builder.rs | 22 +- transaction-pool/src/transactions.rs | 22 +- transaction-pool/src/verifier.rs | 22 +- triehash/CHANGELOG.md | 1 + triehash/Cargo.toml | 2 +- triehash/benches/triehash.rs | 22 +- triehash/src/lib.rs | 22 +- uint/benches/bigint.rs | 2 +- uint/examples/modular.rs | 2 +- uint/fuzz/fuzz_targets/div_mod.rs | 8 + uint/fuzz/fuzz_targets/div_mod_word.rs | 8 + uint/src/lib.rs | 2 +- uint/src/uint.rs | 2 +- uint/tests/uint_tests.rs | 2 +- 139 files changed, 587 insertions(+), 1667 deletions(-) delete mode 100644 LICENSE rename rlp/LICENSE-APACHE2 => LICENSE-APACHE2 (100%) rename rlp/LICENSE-MIT => LICENSE-MIT (95%) rename rlp/license-header => license-header (87%) diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 94a9ed024..000000000 --- a/LICENSE +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/rlp/LICENSE-APACHE2 b/LICENSE-APACHE2 similarity index 100% rename from rlp/LICENSE-APACHE2 rename to LICENSE-APACHE2 diff --git a/rlp/LICENSE-MIT b/LICENSE-MIT similarity index 95% rename from rlp/LICENSE-MIT rename to LICENSE-MIT index cd8fdd2b9..b2d52b66d 100644 --- a/rlp/LICENSE-MIT +++ b/LICENSE-MIT @@ -1,4 +1,4 @@ -Copyright (c) 2015-2017 Parity Technologies +Copyright (c) 2015-2020 Parity Technologies Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/contract-address/CHANGELOG.md b/contract-address/CHANGELOG.md index 927c9dc9c..546bc458e 100644 --- a/contract-address/CHANGELOG.md +++ b/contract-address/CHANGELOG.md @@ -5,3 +5,4 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) diff --git a/contract-address/Cargo.toml b/contract-address/Cargo.toml index 8b4f05682..21486e7a2 100644 --- a/contract-address/Cargo.toml +++ b/contract-address/Cargo.toml @@ -2,7 +2,7 @@ name = "contract-address" version = "0.3.0" authors = ["Parity Technologies "] -license = "MIT" +license = "MIT/Apache2.0" homepage = "https://github.com/paritytech/parity-common" repository = "https://github.com/paritytech/parity-common" description = "A utility crate to create an ethereum contract address" diff --git a/contract-address/src/lib.rs b/contract-address/src/lib.rs index 1d4068d7d..787f8b06f 100644 --- a/contract-address/src/lib.rs +++ b/contract-address/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. #![cfg_attr(feature = "external_doc", feature(external_doc))] #![cfg_attr(feature = "external_doc", doc(include = "../README.md"))] diff --git a/ethbloom/CHANGELOG.md b/ethbloom/CHANGELOG.md index 1edf138b9..677e06714 100644 --- a/ethbloom/CHANGELOG.md +++ b/ethbloom/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog]. ## [Unreleased] - Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) +- License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.8.1] - 2019-10-24 ### Dependencies diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index f9f9960fb..cbf9112a0 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -3,7 +3,7 @@ name = "ethbloom" version = "0.8.1" authors = ["Parity Technologies "] description = "Ethereum bloom filter" -license = "MIT" +license = "MIT/Apache2.0" documentation = "https://docs.rs/ethbloom" homepage = "https://github.com/paritytech/parity-common" repository = "https://github.com/paritytech/parity-common" diff --git a/ethbloom/benches/bloom.rs b/ethbloom/benches/bloom.rs index 005cfd88f..f3de3b7b0 100644 --- a/ethbloom/benches/bloom.rs +++ b/ethbloom/benches/bloom.rs @@ -1,3 +1,11 @@ +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use criterion::{criterion_group, criterion_main, Criterion}; use ethbloom::{Bloom, Input}; use hex_literal::hex; diff --git a/ethbloom/benches/unrolling.rs b/ethbloom/benches/unrolling.rs index 5fd6883ce..647528eb9 100644 --- a/ethbloom/benches/unrolling.rs +++ b/ethbloom/benches/unrolling.rs @@ -1,3 +1,11 @@ +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use criterion::{criterion_group, criterion_main, Criterion}; use crunchy::unroll; use rand::RngCore; diff --git a/ethbloom/src/lib.rs b/ethbloom/src/lib.rs index 49a18214f..c12f5cab8 100644 --- a/ethbloom/src/lib.rs +++ b/ethbloom/src/lib.rs @@ -1,3 +1,11 @@ +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + //! //! ``` //! use hex_literal::hex; diff --git a/ethereum-types/CHANGELOG.md b/ethereum-types/CHANGELOG.md index 6fad76681..1e06ff2b0 100644 --- a/ethereum-types/CHANGELOG.md +++ b/ethereum-types/CHANGELOG.md @@ -5,5 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) + ### Added - uint error type is re-exported (https://github.com/paritytech/parity-common/pull/244) diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index 8153ea823..b706f2873 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -2,7 +2,7 @@ name = "ethereum-types" version = "0.8.0" authors = ["Parity Technologies "] -license = "MIT" +license = "MIT/Apache2.0" homepage = "https://github.com/paritytech/parity-common" description = "Ethereum types" edition = "2018" diff --git a/ethereum-types/src/hash.rs b/ethereum-types/src/hash.rs index 9fe385c5b..9e2057dec 100644 --- a/ethereum-types/src/hash.rs +++ b/ethereum-types/src/hash.rs @@ -1,3 +1,11 @@ +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use crate::{U128, U256, U512, U64}; use fixed_hash::*; use impl_rlp::impl_fixed_hash_rlp; diff --git a/ethereum-types/src/lib.rs b/ethereum-types/src/lib.rs index 9bc756ba0..d94ae57c0 100644 --- a/ethereum-types/src/lib.rs +++ b/ethereum-types/src/lib.rs @@ -1,3 +1,11 @@ +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #![cfg_attr(not(feature = "std"), no_std)] mod hash; diff --git a/ethereum-types/src/uint.rs b/ethereum-types/src/uint.rs index 5cf35feae..87d09541c 100644 --- a/ethereum-types/src/uint.rs +++ b/ethereum-types/src/uint.rs @@ -1,3 +1,11 @@ +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use impl_rlp::impl_uint_rlp; #[cfg(feature = "serialize")] use impl_serde::impl_uint_serde; diff --git a/ethereum-types/tests/serde.rs b/ethereum-types/tests/serde.rs index 4a92241cf..15796c3c7 100644 --- a/ethereum-types/tests/serde.rs +++ b/ethereum-types/tests/serde.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/fixed-hash/CHANGELOG.md b/fixed-hash/CHANGELOG.md index adf179a5e..cfea43299 100644 --- a/fixed-hash/CHANGELOG.md +++ b/fixed-hash/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog]. ## [Unreleased] - Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) +- License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.5.2] - 2019-12-19 ### Fixed diff --git a/fixed-hash/Cargo.toml b/fixed-hash/Cargo.toml index c12d35c57..41bf7d237 100644 --- a/fixed-hash/Cargo.toml +++ b/fixed-hash/Cargo.toml @@ -2,7 +2,7 @@ name = "fixed-hash" version = "0.5.2" authors = ["Parity Technologies "] -license = "MIT" +license = "MIT/Apache2.0" homepage = "https://github.com/paritytech/parity-common" repository = "https://github.com/paritytech/parity-common" description = "Macros to define custom fixed-size hash types" diff --git a/fixed-hash/src/hash.rs b/fixed-hash/src/hash.rs index 46f5c7748..e7fdf0e4c 100644 --- a/fixed-hash/src/hash.rs +++ b/fixed-hash/src/hash.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/fixed-hash/src/lib.rs b/fixed-hash/src/lib.rs index 027ba2284..748101c9f 100644 --- a/fixed-hash/src/lib.rs +++ b/fixed-hash/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/fixed-hash/src/tests.rs b/fixed-hash/src/tests.rs index da14bed13..33c1956b7 100644 --- a/fixed-hash/src/tests.rs +++ b/fixed-hash/src/tests.rs @@ -1,3 +1,11 @@ +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + construct_fixed_hash! { pub struct H32(4); } construct_fixed_hash! { pub struct H64(8); } construct_fixed_hash! { pub struct H128(16); } diff --git a/keccak-hash/CHANGELOG.md b/keccak-hash/CHANGELOG.md index c1208e434..4b6c6795a 100644 --- a/keccak-hash/CHANGELOG.md +++ b/keccak-hash/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.4.1] - 2019-10-24 ### Dependencies diff --git a/keccak-hash/Cargo.toml b/keccak-hash/Cargo.toml index 3d7d88943..49c9506dd 100644 --- a/keccak-hash/Cargo.toml +++ b/keccak-hash/Cargo.toml @@ -5,7 +5,7 @@ description = "`keccak-hash` is a set of utility functions to facilitate working authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" readme = "README.md" -license = "GPL-3.0" +license = "MIT/Apache-2.0" edition = "2018" [dependencies] diff --git a/keccak-hash/benches/keccak_256.rs b/keccak-hash/benches/keccak_256.rs index 5c5794bf5..97e9ee13d 100644 --- a/keccak-hash/benches/keccak_256.rs +++ b/keccak-hash/benches/keccak_256.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use criterion::{black_box, criterion_group, criterion_main, Criterion}; use keccak_hash::keccak; diff --git a/keccak-hash/src/lib.rs b/keccak-hash/src/lib.rs index e66650b39..e9f410672 100644 --- a/keccak-hash/src/lib.rs +++ b/keccak-hash/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. #![cfg_attr(not(feature = "std"), no_std)] diff --git a/kvdb-memorydb/CHANGELOG.md b/kvdb-memorydb/CHANGELOG.md index f2f80a709..cb6163d43 100644 --- a/kvdb-memorydb/CHANGELOG.md +++ b/kvdb-memorydb/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.4.0] - 2019-02-05 - Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) diff --git a/kvdb-memorydb/Cargo.toml b/kvdb-memorydb/Cargo.toml index 954a1e117..24d6a9991 100644 --- a/kvdb-memorydb/Cargo.toml +++ b/kvdb-memorydb/Cargo.toml @@ -4,7 +4,7 @@ version = "0.4.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "A key-value in-memory database that implements the `KeyValueDB` trait" -license = "GPL-3.0" +license = "MIT/Apache-2.0" edition = "2018" [dependencies] diff --git a/kvdb-memorydb/src/lib.rs b/kvdb-memorydb/src/lib.rs index 1f40d24cc..51bac41f0 100644 --- a/kvdb-memorydb/src/lib.rs +++ b/kvdb-memorydb/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2020 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use kvdb::{DBOp, DBTransaction, DBValue, KeyValueDB}; use parity_util_mem::MallocSizeOf; diff --git a/kvdb-rocksdb/CHANGELOG.md b/kvdb-rocksdb/CHANGELOG.md index 10710343c..ac4c2d558 100644 --- a/kvdb-rocksdb/CHANGELOG.md +++ b/kvdb-rocksdb/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.5.0] - 2019-02-05 - Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332 diff --git a/kvdb-rocksdb/Cargo.toml b/kvdb-rocksdb/Cargo.toml index 2f67b8d99..1a51844e9 100644 --- a/kvdb-rocksdb/Cargo.toml +++ b/kvdb-rocksdb/Cargo.toml @@ -4,7 +4,7 @@ version = "0.5.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "kvdb implementation backed by RocksDB" -license = "GPL-3.0" +license = "MIT/Apache-2.0" edition = "2018" [[bench]] diff --git a/kvdb-rocksdb/benches/bench_read_perf.rs b/kvdb-rocksdb/benches/bench_read_perf.rs index 3b4cde3cf..8c17d8981 100644 --- a/kvdb-rocksdb/benches/bench_read_perf.rs +++ b/kvdb-rocksdb/benches/bench_read_perf.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Benchmark RocksDB read performance. //! The benchmark setup consists in writing `NEEDLES * NEEDLES_TO_HAYSTACK_RATIO` 32-bytes random diff --git a/kvdb-rocksdb/src/iter.rs b/kvdb-rocksdb/src/iter.rs index 881aa724e..71482f446 100644 --- a/kvdb-rocksdb/src/iter.rs +++ b/kvdb-rocksdb/src/iter.rs @@ -1,18 +1,10 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! This module contains an implementation of a RocksDB iterator //! wrapped inside a `RwLock`. Since `RwLock` "owns" the inner data, diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index 681883c01..42ee1388c 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2020 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. mod iter; mod stats; diff --git a/kvdb-rocksdb/src/stats.rs b/kvdb-rocksdb/src/stats.rs index 039dd3a88..80fa85ce2 100644 --- a/kvdb-rocksdb/src/stats.rs +++ b/kvdb-rocksdb/src/stats.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2020 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use parking_lot::RwLock; use std::sync::atomic::{AtomicU64, Ordering as AtomicOrdering}; diff --git a/kvdb-shared-tests/Cargo.toml b/kvdb-shared-tests/Cargo.toml index 91259e851..367eef8b6 100644 --- a/kvdb-shared-tests/Cargo.toml +++ b/kvdb-shared-tests/Cargo.toml @@ -4,7 +4,7 @@ version = "0.2.0" authors = ["Parity Technologies "] edition = "2018" description = "Shared tests for kvdb functionality, to be executed against actual implementations" -license = "GPL-3.0" +license = "MIT/Apache2.0" [dependencies] kvdb = { path = "../kvdb", version = "0.4" } diff --git a/kvdb-shared-tests/src/lib.rs b/kvdb-shared-tests/src/lib.rs index 28613c4f3..ca82dc8cd 100644 --- a/kvdb-shared-tests/src/lib.rs +++ b/kvdb-shared-tests/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Shared tests for kvdb functionality, to be executed against actual implementations. diff --git a/kvdb-web/CHANGELOG.md b/kvdb-web/CHANGELOG.md index 69d10f44a..f967e1838 100644 --- a/kvdb-web/CHANGELOG.md +++ b/kvdb-web/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.4.0] - 2019-02-05 - Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) diff --git a/kvdb-web/Cargo.toml b/kvdb-web/Cargo.toml index a686f6b26..284418ca5 100644 --- a/kvdb-web/Cargo.toml +++ b/kvdb-web/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "A key-value database for use in browsers" documentation = "https://docs.rs/kvdb-web/" -license = "GPL-3.0" +license = "MIT/Apache2.0" edition = "2018" [dependencies] diff --git a/kvdb-web/src/error.rs b/kvdb-web/src/error.rs index cd3916174..e88d44636 100644 --- a/kvdb-web/src/error.rs +++ b/kvdb-web/src/error.rs @@ -1,18 +1,10 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Errors that can occur when working with IndexedDB. diff --git a/kvdb-web/src/indexed_db.rs b/kvdb-web/src/indexed_db.rs index 028b60a0a..4593e3007 100644 --- a/kvdb-web/src/indexed_db.rs +++ b/kvdb-web/src/indexed_db.rs @@ -1,18 +1,10 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Utility functions to interact with IndexedDB browser API. diff --git a/kvdb-web/src/lib.rs b/kvdb-web/src/lib.rs index f73426904..5d9878ec2 100644 --- a/kvdb-web/src/lib.rs +++ b/kvdb-web/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! A key-value database for use in browsers //! diff --git a/kvdb-web/tests/indexed_db.rs b/kvdb-web/tests/indexed_db.rs index fe5d8f6a3..81a765a05 100644 --- a/kvdb-web/tests/indexed_db.rs +++ b/kvdb-web/tests/indexed_db.rs @@ -1,18 +1,10 @@ -// Copyright 2019-2020 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! IndexedDB tests. diff --git a/kvdb/CHANGELOG.md b/kvdb/CHANGELOG.md index e202aaa7a..ccec27833 100644 --- a/kvdb/CHANGELOG.md +++ b/kvdb/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.4.0] - 2019-01-06 - Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) diff --git a/kvdb/Cargo.toml b/kvdb/Cargo.toml index e6d738877..c955920a9 100644 --- a/kvdb/Cargo.toml +++ b/kvdb/Cargo.toml @@ -4,7 +4,7 @@ version = "0.4.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Generic key-value trait" -license = "GPL-3.0" +license = "MIT/Apache-2.0" edition = "2018" [dependencies] diff --git a/kvdb/src/io_stats.rs b/kvdb/src/io_stats.rs index d0de5ce36..2f10dc707 100644 --- a/kvdb/src/io_stats.rs +++ b/kvdb/src/io_stats.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Generic statistics for key-value databases diff --git a/kvdb/src/lib.rs b/kvdb/src/lib.rs index afda4af87..6382145ce 100644 --- a/kvdb/src/lib.rs +++ b/kvdb/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Key-Value store abstraction. diff --git a/rlp/license-header b/license-header similarity index 87% rename from rlp/license-header rename to license-header index 03df169c8..67d3f3a1a 100644 --- a/rlp/license-header +++ b/license-header @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/parity-bytes/CHANGELOG.md b/parity-bytes/CHANGELOG.md index cc79bd068..c391629fd 100644 --- a/parity-bytes/CHANGELOG.md +++ b/parity-bytes/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.1.1] - 2019-10-24 ### Dependencies diff --git a/parity-bytes/Cargo.toml b/parity-bytes/Cargo.toml index e49adce31..582d6560e 100644 --- a/parity-bytes/Cargo.toml +++ b/parity-bytes/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.1" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "byte utilities for Parity" -license = "GPL-3.0" +license = "MIT/Apache2.0" edition = "2018" [dependencies] diff --git a/parity-bytes/src/lib.rs b/parity-bytes/src/lib.rs index 292a6e160..e269776d4 100644 --- a/parity-bytes/src/lib.rs +++ b/parity-bytes/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! General bytes-related utilities. //! diff --git a/parity-crypto/CHANGELOG.md b/parity-crypto/CHANGELOG.md index 591ee42d3..debca1116 100644 --- a/parity-crypto/CHANGELOG.md +++ b/parity-crypto/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.5.0] - 2020-02-08 - Remove `inv()` from `SecretKey` (breaking) (https://github.com/paritytech/parity-common/pull/258) diff --git a/parity-crypto/Cargo.toml b/parity-crypto/Cargo.toml index aa5d7b654..0af20678b 100644 --- a/parity-crypto/Cargo.toml +++ b/parity-crypto/Cargo.toml @@ -4,7 +4,7 @@ version = "0.5.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Crypto utils used by ethstore and network." -license = "GPL-3.0" +license = "MIT/Apache-2.0" autobenches = false edition = "2018" diff --git a/parity-crypto/benches/bench.rs b/parity-crypto/benches/bench.rs index 6c13aa369..562c50148 100644 --- a/parity-crypto/benches/bench.rs +++ b/parity-crypto/benches/bench.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use crate::parity_crypto::publickey::Generator; use criterion::{criterion_group, criterion_main, Bencher, Criterion}; diff --git a/parity-crypto/src/aes.rs b/parity-crypto/src/aes.rs index de643dceb..120e4ef3f 100644 --- a/parity-crypto/src/aes.rs +++ b/parity-crypto/src/aes.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use aes::block_cipher_trait::generic_array::GenericArray; use aes::{Aes128, Aes256}; diff --git a/parity-crypto/src/digest.rs b/parity-crypto/src/digest.rs index caf57dd0c..9ec5edf56 100644 --- a/parity-crypto/src/digest.rs +++ b/parity-crypto/src/digest.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use std::marker::PhantomData; use std::ops::Deref; diff --git a/parity-crypto/src/error.rs b/parity-crypto/src/error.rs index 16d67f504..e1a3cceb0 100644 --- a/parity-crypto/src/error.rs +++ b/parity-crypto/src/error.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use std::{error::Error as StdError, fmt, result}; diff --git a/parity-crypto/src/hmac/mod.rs b/parity-crypto/src/hmac/mod.rs index 2b082dd45..6d606fdd7 100644 --- a/parity-crypto/src/hmac/mod.rs +++ b/parity-crypto/src/hmac/mod.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use std::marker::PhantomData; use std::ops::Deref; diff --git a/parity-crypto/src/hmac/test.rs b/parity-crypto/src/hmac/test.rs index 1633cf37c..a13174784 100644 --- a/parity-crypto/src/hmac/test.rs +++ b/parity-crypto/src/hmac/test.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use super::*; use hex_literal::hex; diff --git a/parity-crypto/src/lib.rs b/parity-crypto/src/lib.rs index c6bcb5251..c3049716c 100644 --- a/parity-crypto/src/lib.rs +++ b/parity-crypto/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Crypto utils used by ethstore and network. diff --git a/parity-crypto/src/pbkdf2/mod.rs b/parity-crypto/src/pbkdf2/mod.rs index 099e98893..a3a06e867 100644 --- a/parity-crypto/src/pbkdf2/mod.rs +++ b/parity-crypto/src/pbkdf2/mod.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. pub struct Salt<'a>(pub &'a [u8]); pub struct Secret<'a>(pub &'a [u8]); diff --git a/parity-crypto/src/pbkdf2/test.rs b/parity-crypto/src/pbkdf2/test.rs index ff8cc685c..b0bed84ad 100644 --- a/parity-crypto/src/pbkdf2/test.rs +++ b/parity-crypto/src/pbkdf2/test.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use super::*; diff --git a/parity-crypto/src/publickey/ec_math_utils.rs b/parity-crypto/src/publickey/ec_math_utils.rs index bd8653b79..5ea82a78a 100644 --- a/parity-crypto/src/publickey/ec_math_utils.rs +++ b/parity-crypto/src/publickey/ec_math_utils.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Multiple primitives for work with public and secret keys and with secp256k1 curve points diff --git a/parity-crypto/src/publickey/ecdh.rs b/parity-crypto/src/publickey/ecdh.rs index 8cdaf793a..93a43bed8 100644 --- a/parity-crypto/src/publickey/ecdh.rs +++ b/parity-crypto/src/publickey/ecdh.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! ECDH key agreement scheme implemented as a free function. diff --git a/parity-crypto/src/publickey/ecdsa_signature.rs b/parity-crypto/src/publickey/ecdsa_signature.rs index ae245cffb..6853b1586 100644 --- a/parity-crypto/src/publickey/ecdsa_signature.rs +++ b/parity-crypto/src/publickey/ecdsa_signature.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Signature based on ECDSA, algorithm's description: https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm diff --git a/parity-crypto/src/publickey/ecies.rs b/parity-crypto/src/publickey/ecies.rs index d7c1354f3..3332f8a94 100644 --- a/parity-crypto/src/publickey/ecies.rs +++ b/parity-crypto/src/publickey/ecies.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Functions for ECIES scheme encryption and decryption diff --git a/parity-crypto/src/publickey/error.rs b/parity-crypto/src/publickey/error.rs index 7f9bfb8e0..5ea8ce391 100644 --- a/parity-crypto/src/publickey/error.rs +++ b/parity-crypto/src/publickey/error.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Module specific errors. diff --git a/parity-crypto/src/publickey/extended_keys.rs b/parity-crypto/src/publickey/extended_keys.rs index 44307fdf2..be682db39 100644 --- a/parity-crypto/src/publickey/extended_keys.rs +++ b/parity-crypto/src/publickey/extended_keys.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Secret, public keys extended with the entropy (aka chain code), that allows further key derivation //! Each extended key has 2^31 normal child keys, and 2^31 hardened child keys. diff --git a/parity-crypto/src/publickey/keypair.rs b/parity-crypto/src/publickey/keypair.rs index d4fa13b39..f4ac8b287 100644 --- a/parity-crypto/src/publickey/keypair.rs +++ b/parity-crypto/src/publickey/keypair.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Key pair (public + secret) description. diff --git a/parity-crypto/src/publickey/keypair_generator.rs b/parity-crypto/src/publickey/keypair_generator.rs index 3afd86a97..9dea21de6 100644 --- a/parity-crypto/src/publickey/keypair_generator.rs +++ b/parity-crypto/src/publickey/keypair_generator.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Random key pair generator. Relies on the secp256k1 C-library to generate random data. diff --git a/parity-crypto/src/publickey/mod.rs b/parity-crypto/src/publickey/mod.rs index 8d487b5ad..294d67b38 100644 --- a/parity-crypto/src/publickey/mod.rs +++ b/parity-crypto/src/publickey/mod.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Submodule of crypto utils for working with public key crypto primitives //! If you are looking for git history please refer to the `ethkey` crate in the `parity-ethereum` repository. diff --git a/parity-crypto/src/publickey/secret_key.rs b/parity-crypto/src/publickey/secret_key.rs index 68522ca29..ac938a674 100644 --- a/parity-crypto/src/publickey/secret_key.rs +++ b/parity-crypto/src/publickey/secret_key.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity Ethereum is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity Ethereum. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Secret key implementation. diff --git a/parity-crypto/src/scrypt.rs b/parity-crypto/src/scrypt.rs index eea1931b3..15b7e14e1 100644 --- a/parity-crypto/src/scrypt.rs +++ b/parity-crypto/src/scrypt.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use super::{KEY_LENGTH, KEY_LENGTH_AES}; use crate::error::ScryptError; diff --git a/parity-path/CHANGELOG.md b/parity-path/CHANGELOG.md index 927c9dc9c..fc0263835 100644 --- a/parity-path/CHANGELOG.md +++ b/parity-path/CHANGELOG.md @@ -5,3 +5,4 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) diff --git a/parity-path/Cargo.toml b/parity-path/Cargo.toml index a4096fa73..0c783cf6c 100644 --- a/parity-path/Cargo.toml +++ b/parity-path/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.2" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Path utilities" -license = "GPL-3.0" +license = "MIT/Apache-2.0" edition = "2018" [dependencies] diff --git a/parity-path/src/lib.rs b/parity-path/src/lib.rs index c286678ba..997a040be 100644 --- a/parity-path/src/lib.rs +++ b/parity-path/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Path utilities use std::path::Path; diff --git a/parity-util-mem/CHANGELOG.md b/parity-util-mem/CHANGELOG.md index 855ea42fe..9e99d4c0d 100644 --- a/parity-util-mem/CHANGELOG.md +++ b/parity-util-mem/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.5.1] - 2019-02-05 - Add different mode for malloc_size_of_is_0 macro dealing with generics #334. [#332](https://github.com/paritytech/parity-common/pull/334) diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index d9024ea1c..e0539b23c 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -4,7 +4,7 @@ version = "0.5.1" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Collection of memory related utilities" -license = "GPL-3.0" +license = "MIT/Apache-2.0" edition = "2018" [dependencies] @@ -49,4 +49,4 @@ mimalloc-global = ["mimallocator", "mimalloc-sys"] # implement additional types ethereum-impls = ["ethereum-types", "primitive-types"] # Full estimate: no call to allocator -estimate-heapsize = [] \ No newline at end of file +estimate-heapsize = [] diff --git a/parity-util-mem/derive/Cargo.toml b/parity-util-mem/derive/Cargo.toml index cc208049d..b7648ebd2 100644 --- a/parity-util-mem/derive/Cargo.toml +++ b/parity-util-mem/derive/Cargo.toml @@ -2,7 +2,7 @@ name = "parity-util-mem-derive" version = "0.1.0" authors = ["Parity Technologies "] -license = "MIT" +license = "MIT/Apache2.0" description = "Crate for memory reporting" repository = "https://github.com/paritytech/pariry-common/parity-util-mem/derive" diff --git a/parity-util-mem/derive/lib.rs b/parity-util-mem/derive/lib.rs index c1c1e504e..2331b0aaa 100644 --- a/parity-util-mem/derive/lib.rs +++ b/parity-util-mem/derive/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! A crate for deriving the MallocSizeOf trait. //! diff --git a/parity-util-mem/src/allocators.rs b/parity-util-mem/src/allocators.rs index d2953ecfb..e159a32d0 100644 --- a/parity-util-mem/src/allocators.rs +++ b/parity-util-mem/src/allocators.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! default allocator management //! Features are: diff --git a/parity-util-mem/src/ethereum_impls.rs b/parity-util-mem/src/ethereum_impls.rs index 4379b3b0e..c296d2d40 100644 --- a/parity-util-mem/src/ethereum_impls.rs +++ b/parity-util-mem/src/ethereum_impls.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Implementation of `MallocSize` for common ethereum types: fixed hashes //! and uints. diff --git a/parity-util-mem/src/lib.rs b/parity-util-mem/src/lib.rs index cdea52e42..87b47716a 100644 --- a/parity-util-mem/src/lib.rs +++ b/parity-util-mem/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Crate for parity memory management related utilities. //! It includes global allocator choice, heap measurement and diff --git a/parity-util-mem/src/primitives_impls.rs b/parity-util-mem/src/primitives_impls.rs index ab5953dcc..cf98bc211 100644 --- a/parity-util-mem/src/primitives_impls.rs +++ b/parity-util-mem/src/primitives_impls.rs @@ -1,18 +1,10 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Implementation of `MallocSize` primitive types. diff --git a/parity-util-mem/src/sizeof.rs b/parity-util-mem/src/sizeof.rs index ef63e1000..3d60913e4 100644 --- a/parity-util-mem/src/sizeof.rs +++ b/parity-util-mem/src/sizeof.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Estimation for heapsize calculation. Usable to replace call to allocator method (for some //! allocators or simply because we just need a deterministic cunsumption measurement). diff --git a/parity-util-mem/tests/derive.rs b/parity-util-mem/tests/derive.rs index 87f8c9f50..4fb5f7328 100644 --- a/parity-util-mem/tests/derive.rs +++ b/parity-util-mem/tests/derive.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. #![cfg(feature = "std")] diff --git a/plain_hasher/CHANGELOG.md b/plain_hasher/CHANGELOG.md index a4bd19586..c9970dedd 100644 --- a/plain_hasher/CHANGELOG.md +++ b/plain_hasher/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.2.2] - 2019-10-24 - Migrated to 2018 edition (https://github.com/paritytech/parity-common/pull/213) diff --git a/plain_hasher/Cargo.toml b/plain_hasher/Cargo.toml index 2a7f94989..57cf4d0c1 100644 --- a/plain_hasher/Cargo.toml +++ b/plain_hasher/Cargo.toml @@ -3,7 +3,7 @@ name = "plain_hasher" description = "Hasher for 32-byte keys." version = "0.2.2" authors = ["Parity Technologies "] -license = "MIT" +license = "MIT/Apache2.0" keywords = ["hash", "hasher"] homepage = "https://github.com/paritytech/parity-common" categories = ["no-std"] diff --git a/plain_hasher/benches/bench.rs b/plain_hasher/benches/bench.rs index 4ba53bb1a..e14d9d7d7 100644 --- a/plain_hasher/benches/bench.rs +++ b/plain_hasher/benches/bench.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use std::collections::hash_map::DefaultHasher; use std::hash::Hasher; diff --git a/plain_hasher/src/lib.rs b/plain_hasher/src/lib.rs index 3665995d4..4da4a508b 100644 --- a/plain_hasher/src/lib.rs +++ b/plain_hasher/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. #![cfg_attr(not(feature = "std"), no_std)] diff --git a/primitive-types/Cargo.toml b/primitive-types/Cargo.toml index 3131a001f..e6b53391c 100644 --- a/primitive-types/Cargo.toml +++ b/primitive-types/Cargo.toml @@ -2,7 +2,7 @@ name = "primitive-types" version = "0.6.2" authors = ["Parity Technologies "] -license = "Apache-2.0/MIT" +license = "MIT/Apache2.0" homepage = "https://github.com/paritytech/parity-common" description = "Primitive types shared by Ethereum and Substrate" edition = "2018" diff --git a/primitive-types/impls/codec/Cargo.toml b/primitive-types/impls/codec/Cargo.toml index 12fda74f2..4b39c10af 100644 --- a/primitive-types/impls/codec/Cargo.toml +++ b/primitive-types/impls/codec/Cargo.toml @@ -2,7 +2,7 @@ name = "impl-codec" version = "0.4.2" authors = ["Parity Technologies "] -license = "Apache-2.0/MIT" +license = "MIT/Apache2.0" homepage = "https://github.com/paritytech/parity-common" description = "Parity Codec serialization support for uint and fixed hash." edition = "2018" diff --git a/primitive-types/impls/codec/src/lib.rs b/primitive-types/impls/codec/src/lib.rs index 9e5714ce0..1a4f2e252 100644 --- a/primitive-types/impls/codec/src/lib.rs +++ b/primitive-types/impls/codec/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2018 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/primitive-types/impls/rlp/Cargo.toml b/primitive-types/impls/rlp/Cargo.toml index 62e957c85..85db3c328 100644 --- a/primitive-types/impls/rlp/Cargo.toml +++ b/primitive-types/impls/rlp/Cargo.toml @@ -2,7 +2,7 @@ name = "impl-rlp" version = "0.2.1" authors = ["Parity Technologies "] -license = "Apache-2.0/MIT" +license = "MIT/Apache2.0" homepage = "https://github.com/paritytech/parity-common" description = "RLP serialization support for uint and fixed hash." edition = "2018" diff --git a/primitive-types/impls/rlp/src/lib.rs b/primitive-types/impls/rlp/src/lib.rs index 16a711370..e542c6e6e 100644 --- a/primitive-types/impls/rlp/src/lib.rs +++ b/primitive-types/impls/rlp/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2018 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/primitive-types/impls/serde/Cargo.toml b/primitive-types/impls/serde/Cargo.toml index a57ada2a2..641a59e6a 100644 --- a/primitive-types/impls/serde/Cargo.toml +++ b/primitive-types/impls/serde/Cargo.toml @@ -3,7 +3,7 @@ name = "impl-serde" version = "0.3.0" authors = ["Parity Technologies "] edition = "2018" -license = "Apache-2.0/MIT" +license = "MIT/Apache2.0" homepage = "https://github.com/paritytech/parity-common" description = "Serde serialization support for uint and fixed hash." diff --git a/primitive-types/impls/serde/benches/impl_serde.rs b/primitive-types/impls/serde/benches/impl_serde.rs index d19a97fda..c7a1efea8 100644 --- a/primitive-types/impls/serde/benches/impl_serde.rs +++ b/primitive-types/impls/serde/benches/impl_serde.rs @@ -1,4 +1,4 @@ -// Copyright 2019 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/primitive-types/impls/serde/benches/input.rs b/primitive-types/impls/serde/benches/input.rs index 00d5efdc5..5673f1f52 100644 --- a/primitive-types/impls/serde/benches/input.rs +++ b/primitive-types/impls/serde/benches/input.rs @@ -1,3 +1,11 @@ +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + /// Hexdecimal string 64 chars (32 bytes) pub const HEX_64_CHARS: &str = "\"0x6402541b4e3c2ab65306aec48fce5adedc60e3ac465c3d7036c731e0b2e49209\""; diff --git a/primitive-types/impls/serde/src/lib.rs b/primitive-types/impls/serde/src/lib.rs index 661ff7c0e..500a60cc4 100644 --- a/primitive-types/impls/serde/src/lib.rs +++ b/primitive-types/impls/serde/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2019 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/primitive-types/impls/serde/src/serialize.rs b/primitive-types/impls/serde/src/serialize.rs index 431a56ec7..542ac0dc8 100644 --- a/primitive-types/impls/serde/src/serialize.rs +++ b/primitive-types/impls/serde/src/serialize.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2019 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/primitive-types/src/lib.rs b/primitive-types/src/lib.rs index 5e3f77ec4..0b4af97c8 100644 --- a/primitive-types/src/lib.rs +++ b/primitive-types/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2018 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/rlp/benches/rlp.rs b/rlp/benches/rlp.rs index 1fcd8b21f..d1de4c93b 100644 --- a/rlp/benches/rlp.rs +++ b/rlp/benches/rlp.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/rlp/src/error.rs b/rlp/src/error.rs index d810130b0..a965e5626 100644 --- a/rlp/src/error.rs +++ b/rlp/src/error.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/rlp/src/impls.rs b/rlp/src/impls.rs index 4f30b8a59..c4815019f 100644 --- a/rlp/src/impls.rs +++ b/rlp/src/impls.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/rlp/src/lib.rs b/rlp/src/lib.rs index a4c66e2ac..3a913d69f 100644 --- a/rlp/src/lib.rs +++ b/rlp/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/rlp/src/rlpin.rs b/rlp/src/rlpin.rs index 6cdfaa808..319723c06 100644 --- a/rlp/src/rlpin.rs +++ b/rlp/src/rlpin.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/rlp/src/stream.rs b/rlp/src/stream.rs index 851b845b9..14983d5ef 100644 --- a/rlp/src/stream.rs +++ b/rlp/src/stream.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/rlp/src/traits.rs b/rlp/src/traits.rs index 13531a1b6..b5dfa2764 100644 --- a/rlp/src/traits.rs +++ b/rlp/src/traits.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/rlp/tests/tests.rs b/rlp/tests/tests.rs index 6f51b9bd3..ac8e8d951 100644 --- a/rlp/tests/tests.rs +++ b/rlp/tests/tests.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/trace-time/CHANGELOG.md b/trace-time/CHANGELOG.md index 0231c53a1..0da35007c 100644 --- a/trace-time/CHANGELOG.md +++ b/trace-time/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.1.2] - 2019-10-24 - Migrated to 2018 edition (https://github.com/paritytech/parity-common/pull/232) diff --git a/trace-time/Cargo.toml b/trace-time/Cargo.toml index f1ec6e9a1..fca5a7619 100644 --- a/trace-time/Cargo.toml +++ b/trace-time/Cargo.toml @@ -4,7 +4,7 @@ description = "Easily trace time to execute a scope." version = "0.1.2" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" -license = "GPL-3.0" +license = "MIT/Apache2.0" edition = "2018" [dependencies] diff --git a/trace-time/src/lib.rs b/trace-time/src/lib.rs index 65769ee81..e5ecf2d09 100644 --- a/trace-time/src/lib.rs +++ b/trace-time/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Performance timer with logging diff --git a/transaction-pool/CHANGELOG.md b/transaction-pool/CHANGELOG.md index bcd99d5a9..a054f332b 100644 --- a/transaction-pool/CHANGELOG.md +++ b/transaction-pool/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [2.0.2] - 2019-10-24 - Updated to 2018 edition idioms (https://github.com/paritytech/parity-common/pull/237) diff --git a/transaction-pool/Cargo.toml b/transaction-pool/Cargo.toml index 844607efa..0da12d924 100644 --- a/transaction-pool/Cargo.toml +++ b/transaction-pool/Cargo.toml @@ -2,7 +2,7 @@ description = "Generic transaction pool." name = "transaction-pool" version = "2.0.2" -license = "GPL-3.0" +license = "MIT/Apache2.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" edition = "2018" diff --git a/transaction-pool/src/error.rs b/transaction-pool/src/error.rs index 348082f6a..20935c23b 100644 --- a/transaction-pool/src/error.rs +++ b/transaction-pool/src/error.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use std::{error, fmt, result}; diff --git a/transaction-pool/src/lib.rs b/transaction-pool/src/lib.rs index 66e93fffe..dd49fb3a8 100644 --- a/transaction-pool/src/lib.rs +++ b/transaction-pool/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Generic Transaction Pool //! diff --git a/transaction-pool/src/listener.rs b/transaction-pool/src/listener.rs index 566b318ee..5a3f1a0c7 100644 --- a/transaction-pool/src/listener.rs +++ b/transaction-pool/src/listener.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use crate::error::Error; use std::{ diff --git a/transaction-pool/src/options.rs b/transaction-pool/src/options.rs index 8e1c1002d..947af30a9 100644 --- a/transaction-pool/src/options.rs +++ b/transaction-pool/src/options.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. /// Transaction Pool options. #[derive(Clone, Debug, PartialEq)] diff --git a/transaction-pool/src/pool.rs b/transaction-pool/src/pool.rs index 63bb0a07f..2eb324020 100644 --- a/transaction-pool/src/pool.rs +++ b/transaction-pool/src/pool.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use log::{trace, warn}; use std::collections::{hash_map, BTreeSet, HashMap}; diff --git a/transaction-pool/src/ready.rs b/transaction-pool/src/ready.rs index 45e85ca29..009eae273 100644 --- a/transaction-pool/src/ready.rs +++ b/transaction-pool/src/ready.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. /// Transaction readiness. #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/transaction-pool/src/replace.rs b/transaction-pool/src/replace.rs index a278edb80..cbae6319b 100644 --- a/transaction-pool/src/replace.rs +++ b/transaction-pool/src/replace.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! When queue limits are reached, decide whether to replace an existing transaction from the pool diff --git a/transaction-pool/src/scoring.rs b/transaction-pool/src/scoring.rs index 313bd6bc3..b7f75e7fc 100644 --- a/transaction-pool/src/scoring.rs +++ b/transaction-pool/src/scoring.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! A transactions ordering abstraction. diff --git a/transaction-pool/src/status.rs b/transaction-pool/src/status.rs index b9e7656d4..615e40cb7 100644 --- a/transaction-pool/src/status.rs +++ b/transaction-pool/src/status.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. /// Light pool status. /// This status is cheap to compute and can be called frequently. diff --git a/transaction-pool/src/tests/helpers.rs b/transaction-pool/src/tests/helpers.rs index f757ac8d7..8f6e5fb99 100644 --- a/transaction-pool/src/tests/helpers.rs +++ b/transaction-pool/src/tests/helpers.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use std::cmp; use std::collections::HashMap; diff --git a/transaction-pool/src/tests/mod.rs b/transaction-pool/src/tests/mod.rs index db5ea2885..2d80b4a3d 100644 --- a/transaction-pool/src/tests/mod.rs +++ b/transaction-pool/src/tests/mod.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. mod helpers; mod tx_builder; diff --git a/transaction-pool/src/tests/tx_builder.rs b/transaction-pool/src/tests/tx_builder.rs index 83f7b13a0..d543e830e 100644 --- a/transaction-pool/src/tests/tx_builder.rs +++ b/transaction-pool/src/tests/tx_builder.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use super::{Address, Transaction, H256, U256}; use ethereum_types::BigEndianHash; diff --git a/transaction-pool/src/transactions.rs b/transaction-pool/src/transactions.rs index 5fc963d78..4d6d126af 100644 --- a/transaction-pool/src/transactions.rs +++ b/transaction-pool/src/transactions.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use std::{fmt, mem}; diff --git a/transaction-pool/src/verifier.rs b/transaction-pool/src/verifier.rs index 991b78ebd..d28e5a55e 100644 --- a/transaction-pool/src/verifier.rs +++ b/transaction-pool/src/verifier.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use crate::VerifiedTransaction; diff --git a/triehash/CHANGELOG.md b/triehash/CHANGELOG.md index 320e4f84f..071c96204 100644 --- a/triehash/CHANGELOG.md +++ b/triehash/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.8.2] - 2019-12-15 - Added no-std support (https://github.com/paritytech/parity-common/pull/280) diff --git a/triehash/Cargo.toml b/triehash/Cargo.toml index a941edaa0..407489469 100644 --- a/triehash/Cargo.toml +++ b/triehash/Cargo.toml @@ -4,7 +4,7 @@ version = "0.8.2" authors = ["Parity Technologies "] description = "In-memory patricia trie operations" repository = "https://github.com/paritytech/parity-common" -license = "GPL-3.0" +license = "MIT/Apache2.0" edition = "2018" [dependencies] diff --git a/triehash/benches/triehash.rs b/triehash/benches/triehash.rs index 684484265..14ce0dd6b 100644 --- a/triehash/benches/triehash.rs +++ b/triehash/benches/triehash.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. use criterion::{criterion_group, criterion_main, Criterion}; use ethereum_types::H256; diff --git a/triehash/src/lib.rs b/triehash/src/lib.rs index 81a005826..a60a24998 100644 --- a/triehash/src/lib.rs +++ b/triehash/src/lib.rs @@ -1,18 +1,10 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity. - -// Parity is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Parity is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Parity. If not, see . +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. //! Generetes trie root. //! diff --git a/uint/benches/bigint.rs b/uint/benches/bigint.rs index ea0284cdd..ec36c576a 100644 --- a/uint/benches/bigint.rs +++ b/uint/benches/bigint.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/uint/examples/modular.rs b/uint/examples/modular.rs index abc754f82..30b236992 100644 --- a/uint/examples/modular.rs +++ b/uint/examples/modular.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/uint/fuzz/fuzz_targets/div_mod.rs b/uint/fuzz/fuzz_targets/div_mod.rs index 7bcf751a8..102407ecc 100644 --- a/uint/fuzz/fuzz_targets/div_mod.rs +++ b/uint/fuzz/fuzz_targets/div_mod.rs @@ -1,3 +1,11 @@ +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #![no_main] use libfuzzer_sys::fuzz_target; diff --git a/uint/fuzz/fuzz_targets/div_mod_word.rs b/uint/fuzz/fuzz_targets/div_mod_word.rs index 890774c08..285304944 100644 --- a/uint/fuzz/fuzz_targets/div_mod_word.rs +++ b/uint/fuzz/fuzz_targets/div_mod_word.rs @@ -1,3 +1,11 @@ +// Copyright 2020 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + #![no_main] use libfuzzer_sys::fuzz_target; diff --git a/uint/src/lib.rs b/uint/src/lib.rs index bba720be8..144c53e32 100644 --- a/uint/src/lib.rs +++ b/uint/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/uint/src/uint.rs b/uint/src/uint.rs index 7dd1bca42..ac0ffc85e 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2017 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/uint/tests/uint_tests.rs b/uint/tests/uint_tests.rs index ddeb747c3..2e226ad36 100644 --- a/uint/tests/uint_tests.rs +++ b/uint/tests/uint_tests.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2019 Parity Technologies +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license From e5dd7d46155664f49b46ab865ac3427d27232d56 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Thu, 13 Feb 2020 14:00:06 +0100 Subject: [PATCH 25/56] prepare rlp-derive release (#344) * rlp-derive: unify license headers and prepare for publishing * unify changelog formats * parity-runtime: was published recently --- ethbloom/CHANGELOG.md | 2 +- ethereum-types/CHANGELOG.md | 4 ++-- fixed-hash/CHANGELOG.md | 4 ++-- keccak-hash/CHANGELOG.md | 4 ++-- kvdb-memorydb/CHANGELOG.md | 1 - kvdb-rocksdb/CHANGELOG.md | 22 +++++++++++----------- kvdb-shared-tests/CHANGELOG.md | 7 +++++++ kvdb-web/CHANGELOG.md | 2 +- kvdb/CHANGELOG.md | 6 +++--- parity-bytes/CHANGELOG.md | 6 +++--- parity-crypto/CHANGELOG.md | 16 ++++++++-------- parity-util-mem/CHANGELOG.md | 6 +++--- parity-util-mem/derive/CHANGELOG.md | 7 +++++++ plain_hasher/CHANGELOG.md | 6 +++--- primitive-types/CHANGELOG.md | 2 +- primitive-types/impls/serde/CHANGELOG.md | 2 +- rlp-derive/CHANGELOG.md | 2 +- rlp-derive/Cargo.toml | 2 +- rlp-derive/src/de.rs | 2 +- rlp-derive/src/en.rs | 2 +- rlp-derive/src/lib.rs | 2 +- rlp-derive/tests/rlp.rs | 2 +- rlp/CHANGELOG.md | 10 +++++----- runtime/CHANGELOG.md | 4 ++-- trace-time/CHANGELOG.md | 6 +++--- transaction-pool/CHANGELOG.md | 6 +++--- triehash/CHANGELOG.md | 8 ++++---- uint/CHANGELOG.md | 10 +++++----- 28 files changed, 83 insertions(+), 70 deletions(-) create mode 100644 kvdb-shared-tests/CHANGELOG.md create mode 100644 parity-util-mem/derive/CHANGELOG.md diff --git a/ethbloom/CHANGELOG.md b/ethbloom/CHANGELOG.md index 677e06714..6c13f6f0a 100644 --- a/ethbloom/CHANGELOG.md +++ b/ethbloom/CHANGELOG.md @@ -10,4 +10,4 @@ The format is based on [Keep a Changelog]. ## [0.8.1] - 2019-10-24 ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) diff --git a/ethereum-types/CHANGELOG.md b/ethereum-types/CHANGELOG.md index 1e06ff2b0..6b214e75b 100644 --- a/ethereum-types/CHANGELOG.md +++ b/ethereum-types/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ @@ -8,4 +8,4 @@ The format is based on [Keep a Changelog]. - License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ### Added -- uint error type is re-exported (https://github.com/paritytech/parity-common/pull/244) +- Uint error type is re-exported. [#244](https://github.com/paritytech/parity-common/pull/244) diff --git a/fixed-hash/CHANGELOG.md b/fixed-hash/CHANGELOG.md index cfea43299..f486d7847 100644 --- a/fixed-hash/CHANGELOG.md +++ b/fixed-hash/CHANGELOG.md @@ -10,8 +10,8 @@ The format is based on [Keep a Changelog]. ## [0.5.2] - 2019-12-19 ### Fixed -- re-export `alloc` for both std and no-std to fix compilation (See [PR #268](https://github.com/paritytech/parity-common/pull/268)) +- Re-export `alloc` for both std and no-std to fix compilation. [#268](https://github.com/paritytech/parity-common/pull/268) ## [0.5.1] - 2019-10-24 ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) diff --git a/keccak-hash/CHANGELOG.md b/keccak-hash/CHANGELOG.md index 4b6c6795a..429e3bc13 100644 --- a/keccak-hash/CHANGELOG.md +++ b/keccak-hash/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ @@ -9,4 +9,4 @@ The format is based on [Keep a Changelog]. ## [0.4.1] - 2019-10-24 ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) diff --git a/kvdb-memorydb/CHANGELOG.md b/kvdb-memorydb/CHANGELOG.md index cb6163d43..3da9b9203 100644 --- a/kvdb-memorydb/CHANGELOG.md +++ b/kvdb-memorydb/CHANGELOG.md @@ -19,7 +19,6 @@ The format is based on [Keep a Changelog]. ## [0.2.0] - 2019-12-19 ### Fixed - `iter_from_prefix` behaviour synced with the `kvdb-rocksdb` - ### Changed - Default column support removed from the API - Column argument type changed from `Option` to `u32` diff --git a/kvdb-rocksdb/CHANGELOG.md b/kvdb-rocksdb/CHANGELOG.md index ac4c2d558..dbebb5087 100644 --- a/kvdb-rocksdb/CHANGELOG.md +++ b/kvdb-rocksdb/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog]. - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.5.0] - 2019-02-05 -- Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332 +- Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) ## [0.4.2] - 2019-02-04 ### Fixes @@ -22,10 +22,10 @@ The format is based on [Keep a Changelog]. - Support querying memory footprint via `MallocSizeOf` trait. [#292](https://github.com/paritytech/parity-common/pull/292) ## [0.3.0] - 2019-12-19 -- Use `get_pinned` API to save one allocation for each call to `get()` (See [PR #274](https://github.com/paritytech/parity-common/pull/274) for details) -- Rename `drop_column` to `remove_last_column` (See [PR #274](https://github.com/paritytech/parity-common/pull/274) for details) -- Rename `get_cf` to `cf` (See [PR #274](https://github.com/paritytech/parity-common/pull/274) for details) -- Default column support removed from the API (See [PR #278](https://github.com/paritytech/parity-common/pull/278) for details) +- Use `get_pinned` API to save one allocation for each call to `get()`. [#274](https://github.com/paritytech/parity-common/pull/274) +- Rename `drop_column` to `remove_last_column`. [#274](https://github.com/paritytech/parity-common/pull/274) +- Rename `get_cf` to `cf`. [#274](https://github.com/paritytech/parity-common/pull/274) +- Default column support removed from the API. [#278](https://github.com/paritytech/parity-common/pull/278) - Column argument type changed from `Option` to `u32` - Migration - Column index `None` -> unsupported, `Some(0)` -> `0`, `Some(1)` -> `1`, etc. @@ -33,16 +33,16 @@ The format is based on [Keep a Changelog]. - `DatabaseConfig::default()` defaults to 1 column - `Database::with_columns` still accepts `u32`, but panics if `0` is provided - `Database::open` panics if configuration with 0 columns is provided -- Add `num_keys(col)` to get an estimate of the number of keys in a column (See [PR #285](https://github.com/paritytech/parity-common/pull/285)). -- Remove `ElasticArray` and use the new `DBValue` (alias for `Vec`) and `DBKey` types from `kvdb`. (See [PR #282](https://github.com/paritytech/parity-common/pull/282/files)) +- Add `num_keys(col)` to get an estimate of the number of keys in a column. [#285](https://github.com/paritytech/parity-common/pull/285) +- Remove `ElasticArray` and use the new `DBValue` (alias for `Vec`) and `DBKey` types from `kvdb`. [#282](https://github.com/paritytech/parity-common/pull/282) ## [0.2.0] - 2019-11-28 -- Switched away from using [parity-rocksdb](https://crates.io/crates/parity-rocksdb) in favour of upstream [rust-rocksdb](https://crates.io/crates/rocksdb) (see [PR #257](https://github.com/paritytech/parity-common/pull/257) for details) -- Revamped configuration handling, allowing per-column memory budgeting (see [PR #256](https://github.com/paritytech/parity-common/pull/256) for details) +- Switched away from using [parity-rocksdb](https://crates.io/crates/parity-rocksdb) in favour of upstream [rust-rocksdb](https://crates.io/crates/rocksdb). [#257](https://github.com/paritytech/parity-common/pull/257) +- Revamped configuration handling, allowing per-column memory budgeting. [#256](https://github.com/paritytech/parity-common/pull/256) ### Dependencies - rust-rocksdb v0.13 ## [0.1.6] - 2019-10-24 -- Updated to 2018 edition idioms (https://github.com/paritytech/parity-common/pull/237) +- Updated to 2018 edition idioms. [#237](https://github.com/paritytech/parity-common/pull/237) ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) diff --git a/kvdb-shared-tests/CHANGELOG.md b/kvdb-shared-tests/CHANGELOG.md new file mode 100644 index 000000000..545cf7dff --- /dev/null +++ b/kvdb-shared-tests/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] diff --git a/kvdb-web/CHANGELOG.md b/kvdb-web/CHANGELOG.md index f967e1838..0d4a23ad9 100644 --- a/kvdb-web/CHANGELOG.md +++ b/kvdb-web/CHANGELOG.md @@ -24,4 +24,4 @@ The format is based on [Keep a Changelog]. ## [0.1.1] - 2019-10-24 ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) diff --git a/kvdb/CHANGELOG.md b/kvdb/CHANGELOG.md index ccec27833..c7d38231b 100644 --- a/kvdb/CHANGELOG.md +++ b/kvdb/CHANGELOG.md @@ -22,10 +22,10 @@ The format is based on [Keep a Changelog]. - Default column support removed from the API - Column argument type changed from `Option` to `u32` - Migration `None` -> unsupported, `Some(0)` -> `0`, `Some(1)` -> `1`, etc. -- Remove `ElasticArray` and change `DBValue` to be a type alias for `Vec` and add a `DBKey` backed by a `SmallVec`. (See [PR #282](https://github.com/paritytech/parity-common/pull/282/files)) +- Remove `ElasticArray` and change `DBValue` to be a type alias for `Vec` and add a `DBKey` backed by a `SmallVec`. [#282](https://github.com/paritytech/parity-common/pull/282) ## [0.1.1] - 2019-10-24 ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) ### Changed -- Migrated to 2018 edition (https://github.com/paritytech/parity-common/pull/205) +- Migrated to 2018 edition. [#205](https://github.com/paritytech/parity-common/pull/205) diff --git a/parity-bytes/CHANGELOG.md b/parity-bytes/CHANGELOG.md index c391629fd..ef8a2633d 100644 --- a/parity-bytes/CHANGELOG.md +++ b/parity-bytes/CHANGELOG.md @@ -9,6 +9,6 @@ The format is based on [Keep a Changelog]. ## [0.1.1] - 2019-10-24 ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) -### Added -- Added no-std support (https://github.com/paritytech/parity-common/pull/154) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) +### Added +- Added no-std support. [#154](https://github.com/paritytech/parity-common/pull/154) diff --git a/parity-crypto/CHANGELOG.md b/parity-crypto/CHANGELOG.md index debca1116..c955084f9 100644 --- a/parity-crypto/CHANGELOG.md +++ b/parity-crypto/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ @@ -8,10 +8,10 @@ The format is based on [Keep a Changelog]. - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.5.0] - 2020-02-08 -- Remove `inv()` from `SecretKey` (breaking) (https://github.com/paritytech/parity-common/pull/258) -- `Generate::generate()` does not return error (https://github.com/paritytech/parity-common/pull/258) -- `Secp256k1` is no longer exported (https://github.com/paritytech/parity-common/pull/258) -- Remove `public_is_valid()` as it is now impossible to create invalid public keys (https://github.com/paritytech/parity-common/pull/258) -- 0-valued `Secp::Message`s are disallowed (signatures on them are forgeable for all keys) (https://github.com/paritytech/parity-common/pull/258) -- Switch to upstream `rust-secp256k1` at v0.17.2 (https://github.com/paritytech/parity-common/pull/258) -- make `rustc_hex` dependency optional (https://github.com/paritytech/parity-common/pull/337) +- Remove `inv()` from `SecretKey` (breaking). [#258](https://github.com/paritytech/parity-common/pull/258) +- `Generate::generate()` does not return error. [#258](https://github.com/paritytech/parity-common/pull/258) +- `Secp256k1` is no longer exported. [#258](https://github.com/paritytech/parity-common/pull/258) +- Remove `public_is_valid()` as it is now impossible to create invalid public keys. [#258](https://github.com/paritytech/parity-common/pull/258) +- 0-valued `Secp::Message`s are disallowed (signatures on them are forgeable for all keys). [#258](https://github.com/paritytech/parity-common/pull/258) +- Switch to upstream `rust-secp256k1` at v0.17.2. [#258](https://github.com/paritytech/parity-common/pull/258) +- make `rustc_hex` dependency optional. [#337](https://github.com/paritytech/parity-common/pull/337) diff --git a/parity-util-mem/CHANGELOG.md b/parity-util-mem/CHANGELOG.md index 9e99d4c0d..dbab86b6e 100644 --- a/parity-util-mem/CHANGELOG.md +++ b/parity-util-mem/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog]. - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.5.1] - 2019-02-05 -- Add different mode for malloc_size_of_is_0 macro dealing with generics #334. [#332](https://github.com/paritytech/parity-common/pull/334) +- Add different mode for malloc_size_of_is_0 macro dealing with generics. [#334](https://github.com/paritytech/parity-common/pull/334) ## [0.5.0] - 2019-02-05 - Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) @@ -27,8 +27,8 @@ The format is based on [Keep a Changelog]. - Added default implementation of `MallocSizeOf` for tuples up to 12. [#300](https://github.com/paritytech/parity-common/pull/300) ## [0.3.0] - 2019-12-19 -- Remove `MallocSizeOf` impls for `ElasticArray` and implement it for `SmallVec` (32 and 36). (See [PR #282](https://github.com/paritytech/parity-common/pull/282/files)) +- Remove `MallocSizeOf` impls for `ElasticArray` and implement it for `SmallVec` (32 and 36). [#282](https://github.com/paritytech/parity-common/pull/282) ## [0.2.1] - 2019-10-24 ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) diff --git a/parity-util-mem/derive/CHANGELOG.md b/parity-util-mem/derive/CHANGELOG.md new file mode 100644 index 000000000..545cf7dff --- /dev/null +++ b/parity-util-mem/derive/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +The format is based on [Keep a Changelog]. + +[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ + +## [Unreleased] diff --git a/plain_hasher/CHANGELOG.md b/plain_hasher/CHANGELOG.md index c9970dedd..afc302090 100644 --- a/plain_hasher/CHANGELOG.md +++ b/plain_hasher/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ @@ -8,6 +8,6 @@ The format is based on [Keep a Changelog]. - License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.2.2] - 2019-10-24 -- Migrated to 2018 edition (https://github.com/paritytech/parity-common/pull/213) +- Migrated to 2018 edition. [#213](https://github.com/paritytech/parity-common/pull/213) ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) diff --git a/primitive-types/CHANGELOG.md b/primitive-types/CHANGELOG.md index 87ee03e6f..0689eab5a 100644 --- a/primitive-types/CHANGELOG.md +++ b/primitive-types/CHANGELOG.md @@ -12,4 +12,4 @@ The format is based on [Keep a Changelog]. ## [0.6.1] - 2019-10-24 ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) diff --git a/primitive-types/impls/serde/CHANGELOG.md b/primitive-types/impls/serde/CHANGELOG.md index a63cfb2f1..e58aeb12c 100644 --- a/primitive-types/impls/serde/CHANGELOG.md +++ b/primitive-types/impls/serde/CHANGELOG.md @@ -8,4 +8,4 @@ The format is based on [Keep a Changelog]. ## [0.2.3] - 2019-10-29 ### Fixed -- Fixed a bug in empty slice serialization (https://github.com/paritytech/parity-common/pull/253) +- Fixed a bug in empty slice serialization. [#253](https://github.com/paritytech/parity-common/pull/253) diff --git a/rlp-derive/CHANGELOG.md b/rlp-derive/CHANGELOG.md index 592d3fbf9..d7b344b76 100644 --- a/rlp-derive/CHANGELOG.md +++ b/rlp-derive/CHANGELOG.md @@ -6,5 +6,5 @@ The format is based on [Keep a Changelog]. ## [Unreleased] -## [0.1.0] - 2020-02-12 +## [0.1.0] - 2020-02-13 - Extracted from parity-ethereum repo. [#343](https://github.com/paritytech/parity-common/pull/343) diff --git a/rlp-derive/Cargo.toml b/rlp-derive/Cargo.toml index bf4d0eaf0..de3824a2f 100644 --- a/rlp-derive/Cargo.toml +++ b/rlp-derive/Cargo.toml @@ -16,4 +16,4 @@ quote = "1.0.2" proc-macro2 = "1.0.8" [dev-dependencies] -rlp = "0.4.0" +rlp = "0.4.4" diff --git a/rlp-derive/src/de.rs b/rlp-derive/src/de.rs index d1b4e4ca5..490c1a7f4 100644 --- a/rlp-derive/src/de.rs +++ b/rlp-derive/src/de.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2020 Parity Technologies (UK) Ltd. +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/rlp-derive/src/en.rs b/rlp-derive/src/en.rs index 9eb0d6afb..631862429 100644 --- a/rlp-derive/src/en.rs +++ b/rlp-derive/src/en.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2020 Parity Technologies (UK) Ltd. +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/rlp-derive/src/lib.rs b/rlp-derive/src/lib.rs index 47efd2ffe..6ec9cb510 100644 --- a/rlp-derive/src/lib.rs +++ b/rlp-derive/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2020 Parity Technologies (UK) Ltd. +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/rlp-derive/tests/rlp.rs b/rlp-derive/tests/rlp.rs index e3cda4dbc..fd564dc7d 100644 --- a/rlp-derive/tests/rlp.rs +++ b/rlp-derive/tests/rlp.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2020 Parity Technologies (UK) Ltd. +// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license diff --git a/rlp/CHANGELOG.md b/rlp/CHANGELOG.md index e0a32ca9b..c817dc6b9 100644 --- a/rlp/CHANGELOG.md +++ b/rlp/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ @@ -8,12 +8,12 @@ The format is based on [Keep a Changelog]. ## [0.4.4] - 2019-11-20 ### Added -- Method `Rlp::at_with_offset` (https://github.com/paritytech/parity-common/pull/269) +- Method `Rlp::at_with_offset`. [#269](https://github.com/paritytech/parity-common/pull/269) ## [0.4.3] - 2019-10-24 ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) ### Fixed -- Fixed nested unbounded lists (https://github.com/paritytech/parity-common/pull/203) +- Fixed nested unbounded lists. [#203](https://github.com/paritytech/parity-common/pull/203) ### Added -- Added no-std support (https://github.com/paritytech/parity-common/pull/206) +- Added no-std support. [#206](https://github.com/paritytech/parity-common/pull/206) diff --git a/runtime/CHANGELOG.md b/runtime/CHANGELOG.md index 59d2c7ffe..e73fb6f28 100644 --- a/runtime/CHANGELOG.md +++ b/runtime/CHANGELOG.md @@ -6,6 +6,6 @@ The format is based on [Keep a Changelog]. ## [Unreleased] -## [0.1.1] - 2019-11-25 +## [0.1.1] - 2020-02-11 ### Changed -- Moved to parity common repo, prepared for publishing (https://github.com/paritytech/parity-common/pull/271) +- Moved to parity common repo, prepared for publishing. [#271](https://github.com/paritytech/parity-common/pull/271) diff --git a/trace-time/CHANGELOG.md b/trace-time/CHANGELOG.md index 0da35007c..300ce6461 100644 --- a/trace-time/CHANGELOG.md +++ b/trace-time/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ @@ -8,6 +8,6 @@ The format is based on [Keep a Changelog]. - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.1.2] - 2019-10-24 -- Migrated to 2018 edition (https://github.com/paritytech/parity-common/pull/232) +- Migrated to 2018 edition. [#232](https://github.com/paritytech/parity-common/pull/232) ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) diff --git a/transaction-pool/CHANGELOG.md b/transaction-pool/CHANGELOG.md index a054f332b..431effd94 100644 --- a/transaction-pool/CHANGELOG.md +++ b/transaction-pool/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ @@ -8,6 +8,6 @@ The format is based on [Keep a Changelog]. - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [2.0.2] - 2019-10-24 -- Updated to 2018 edition idioms (https://github.com/paritytech/parity-common/pull/237) +- Updated to 2018 edition idioms. [#237](https://github.com/paritytech/parity-common/pull/237) ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) diff --git a/triehash/CHANGELOG.md b/triehash/CHANGELOG.md index 071c96204..88acd4dd1 100644 --- a/triehash/CHANGELOG.md +++ b/triehash/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ @@ -8,8 +8,8 @@ The format is based on [Keep a Changelog]. - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.8.2] - 2019-12-15 -- Added no-std support (https://github.com/paritytech/parity-common/pull/280) +- Added no-std support. [#280](https://github.com/paritytech/parity-common/pull/280) ## [0.8.1] - 2019-10-24 -- Migrated to 2018 edition (https://github.com/paritytech/parity-common/pull/214) +- Migrated to 2018 edition. [#214](https://github.com/paritytech/parity-common/pull/214) ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) diff --git a/uint/CHANGELOG.md b/uint/CHANGELOG.md index a4214eaf9..c04300e84 100644 --- a/uint/CHANGELOG.md +++ b/uint/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -The format is based on [Keep a Changelog]. +The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ @@ -8,9 +8,9 @@ The format is based on [Keep a Changelog]. ## [0.8.2] - 2019-10-24 ### Fixed -- Fixed 2018 edition imports (https://github.com/paritytech/parity-common/pull/237) -- Removed `uninitialized` usage (https://github.com/paritytech/parity-common/pull/238) +- Fixed 2018 edition imports. [#237](https://github.com/paritytech/parity-common/pull/237) +- Removed `uninitialized` usage. [#238](https://github.com/paritytech/parity-common/pull/238) ### Dependencies -- Updated dependencies (https://github.com/paritytech/parity-common/pull/239) +- Updated dependencies. [#239](https://github.com/paritytech/parity-common/pull/239) ### Changed -- Modified AsRef impl (https://github.com/paritytech/parity-common/pull/196) +- Modified AsRef impl. [#196](https://github.com/paritytech/parity-common/pull/196) From 3ca30bf82d08c972d4affd78055435351cdde2ef Mon Sep 17 00:00:00 2001 From: Artem Vorotnikov Date: Fri, 21 Feb 2020 13:05:50 +0300 Subject: [PATCH 26/56] Fix clippy lints for rlp-derive (#345) --- rlp-derive/src/de.rs | 74 ++++++++++++++++++++--------------------- rlp-derive/src/en.rs | 67 +++++++++++++++++++------------------ rlp-derive/src/lib.rs | 2 ++ rlp-derive/tests/rlp.rs | 40 +++++++++++----------- 4 files changed, 93 insertions(+), 90 deletions(-) diff --git a/rlp-derive/src/de.rs b/rlp-derive/src/de.rs index 490c1a7f4..730c39270 100644 --- a/rlp-derive/src/de.rs +++ b/rlp-derive/src/de.rs @@ -24,9 +24,10 @@ fn decodable_wrapper_parse_quotes() -> ParseQuotes { } pub fn impl_decodable(ast: &syn::DeriveInput) -> TokenStream { - let body = match ast.data { - syn::Data::Struct(ref s) => s, - _ => panic!("#[derive(RlpDecodable)] is only defined for structs."), + let body = if let syn::Data::Struct(s) = &ast.data { + s + } else { + panic!("#[derive(RlpDecodable)] is only defined for structs."); }; let mut default_attribute_encountered = false; @@ -59,9 +60,10 @@ pub fn impl_decodable(ast: &syn::DeriveInput) -> TokenStream { } pub fn impl_decodable_wrapper(ast: &syn::DeriveInput) -> TokenStream { - let body = match ast.data { - syn::Data::Struct(ref s) => s, - _ => panic!("#[derive(RlpDecodableWrapper)] is only defined for structs."), + let body = if let syn::Data::Struct(s) = &ast.data { + s + } else { + panic!("#[derive(RlpDecodableWrapper)] is only defined for structs."); }; let stmt = { @@ -98,20 +100,21 @@ pub fn impl_decodable_wrapper(ast: &syn::DeriveInput) -> TokenStream { } fn decodable_field( - index: usize, + mut index: usize, field: &syn::Field, quotes: ParseQuotes, default_attribute_encountered: &mut bool, ) -> TokenStream { - let id = match field.ident { - Some(ref ident) => quote! { #ident }, - None => { - let index: syn::Index = index.into(); - quote! { #index } - } + let id = if let Some(ident) = &field.ident { + quote! { #ident } + } else { + let index = syn::Index::from(index); + quote! { #index } }; - let index = index - *default_attribute_encountered as usize; + if *default_attribute_encountered { + index -= 1; + } let index = quote! { #index }; let single = quotes.single; @@ -123,7 +126,7 @@ fn decodable_field( panic!("only 1 #[rlp(default)] attribute is allowed in a struct") } match attr.parse_args() { - Ok(proc_macro2::TokenTree::Ident(ident)) if ident.to_string() == "default" => {} + Ok(proc_macro2::TokenTree::Ident(ident)) if ident == "default" => {} _ => panic!("only #[rlp(default)] attribute is supported"), } *default_attribute_encountered = true; @@ -132,32 +135,29 @@ fn decodable_field( false }; - match field.ty { - syn::Type::Path(ref path) => { - let ident = &path.path.segments.first().expect("there must be at least 1 segment").ident; - let ident_type = ident.to_string(); - if &ident_type == "Vec" { - if quotes.takes_index { - if default { - quote! { #id: #list(#index).unwrap_or_default(), } - } else { - quote! { #id: #list(#index)?, } - } + if let syn::Type::Path(path) = &field.ty { + let ident = &path.path.segments.first().expect("there must be at least 1 segment").ident; + let ident_type = ident.to_string(); + if ident_type == "Vec" { + if quotes.takes_index { + if default { + quote! { #id: #list(#index).unwrap_or_default(), } } else { - quote! { #id: #list()?, } + quote! { #id: #list(#index)?, } } } else { - if quotes.takes_index { - if default { - quote! { #id: #single(#index).unwrap_or_default(), } - } else { - quote! { #id: #single(#index)?, } - } - } else { - quote! { #id: #single()?, } - } + quote! { #id: #list()?, } + } + } else if quotes.takes_index { + if default { + quote! { #id: #single(#index).unwrap_or_default(), } + } else { + quote! { #id: #single(#index)?, } } + } else { + quote! { #id: #single()?, } } - _ => panic!("rlp_derive not supported"), + } else { + panic!("rlp_derive not supported"); } } diff --git a/rlp-derive/src/en.rs b/rlp-derive/src/en.rs index 631862429..9c21bebd2 100644 --- a/rlp-derive/src/en.rs +++ b/rlp-derive/src/en.rs @@ -10,9 +10,10 @@ use proc_macro2::TokenStream; use quote::quote; pub fn impl_encodable(ast: &syn::DeriveInput) -> TokenStream { - let body = match ast.data { - syn::Data::Struct(ref s) => s, - _ => panic!("#[derive(RlpEncodable)] is only defined for structs."), + let body = if let syn::Data::Struct(s) = &ast.data { + s + } else { + panic!("#[derive(RlpEncodable)] is only defined for structs."); }; let stmts: Vec<_> = body.fields.iter().enumerate().map(|(i, field)| encodable_field(i, field)).collect(); @@ -38,9 +39,10 @@ pub fn impl_encodable(ast: &syn::DeriveInput) -> TokenStream { } pub fn impl_encodable_wrapper(ast: &syn::DeriveInput) -> TokenStream { - let body = match ast.data { - syn::Data::Struct(ref s) => s, - _ => panic!("#[derive(RlpEncodableWrapper)] is only defined for structs."), + let body = if let syn::Data::Struct(s) = &ast.data { + s + } else { + panic!("#[derive(RlpEncodableWrapper)] is only defined for structs."); }; let stmt = { @@ -72,38 +74,37 @@ pub fn impl_encodable_wrapper(ast: &syn::DeriveInput) -> TokenStream { } fn encodable_field(index: usize, field: &syn::Field) -> TokenStream { - let ident = match field.ident { - Some(ref ident) => quote! { #ident }, - None => { - let index: syn::Index = index.into(); - quote! { #index } - } + let ident = if let Some(ident) = &field.ident { + quote! { #ident } + } else { + let index = syn::Index::from(index); + quote! { #index } }; let id = quote! { self.#ident }; - match field.ty { - syn::Type::Path(ref path) => { - let top_segment = path.path.segments.first().expect("there must be at least 1 segment"); - let ident = &top_segment.ident; - if &ident.to_string() == "Vec" { - let inner_ident = match top_segment.arguments { - syn::PathArguments::AngleBracketed(ref angle) => { - let ty = angle.args.first().expect("Vec has only one angle bracketed type; qed"); - match *ty { - syn::GenericArgument::Type(syn::Type::Path(ref path)) => { - &path.path.segments.first().expect("there must be at least 1 segment").ident - } - _ => panic!("rlp_derive not supported"), - } + if let syn::Type::Path(path) = &field.ty { + let top_segment = path.path.segments.first().expect("there must be at least 1 segment"); + let ident = &top_segment.ident; + if ident == "Vec" { + let inner_ident = { + if let syn::PathArguments::AngleBracketed(angle) = &top_segment.arguments { + if let syn::GenericArgument::Type(syn::Type::Path(path)) = + angle.args.first().expect("Vec has only one angle bracketed type; qed") + { + &path.path.segments.first().expect("there must be at least 1 segment").ident + } else { + panic!("rlp_derive not supported"); } - _ => unreachable!("Vec has only one angle bracketed type; qed"), - }; - quote! { stream.append_list::<#inner_ident, _>(&#id); } - } else { - quote! { stream.append(&#id); } - } + } else { + unreachable!("Vec has only one angle bracketed type; qed") + } + }; + quote! { stream.append_list::<#inner_ident, _>(&#id); } + } else { + quote! { stream.append(&#id); } } - _ => panic!("rlp_derive not supported"), + } else { + panic!("rlp_derive not supported"); } } diff --git a/rlp-derive/src/lib.rs b/rlp-derive/src/lib.rs index 6ec9cb510..cf6edb4f4 100644 --- a/rlp-derive/src/lib.rs +++ b/rlp-derive/src/lib.rs @@ -16,6 +16,8 @@ //! the field deserialization fails, as we don't serialize field //! names and there is no way to tell if it is present or not. +#![warn(clippy::all, clippy::pedantic, clippy::nursery)] + extern crate proc_macro; mod de; diff --git a/rlp-derive/tests/rlp.rs b/rlp-derive/tests/rlp.rs index fd564dc7d..24963d323 100644 --- a/rlp-derive/tests/rlp.rs +++ b/rlp-derive/tests/rlp.rs @@ -10,62 +10,62 @@ use rlp::{decode, encode}; use rlp_derive::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; #[derive(Debug, PartialEq, RlpEncodable, RlpDecodable)] -struct Foo { +struct Item { a: String, } #[derive(Debug, PartialEq, RlpEncodableWrapper, RlpDecodableWrapper)] -struct FooWrapper { +struct ItemWrapper { a: String, } #[test] -fn test_encode_foo() { - let foo = Foo { a: "cat".into() }; +fn test_encode_item() { + let item = Item { a: "cat".into() }; let expected = vec![0xc4, 0x83, b'c', b'a', b't']; - let out = encode(&foo); + let out = encode(&item); assert_eq!(out, expected); let decoded = decode(&expected).expect("decode failure"); - assert_eq!(foo, decoded); + assert_eq!(item, decoded); } #[test] -fn test_encode_foo_wrapper() { - let foo = FooWrapper { a: "cat".into() }; +fn test_encode_item_wrapper() { + let item = ItemWrapper { a: "cat".into() }; let expected = vec![0x83, b'c', b'a', b't']; - let out = encode(&foo); + let out = encode(&item); assert_eq!(out, expected); let decoded = decode(&expected).expect("decode failure"); - assert_eq!(foo, decoded); + assert_eq!(item, decoded); } #[test] -fn test_encode_foo_default() { +fn test_encode_item_default() { #[derive(Debug, PartialEq, RlpEncodable, RlpDecodable)] - struct FooDefault { + struct ItemDefault { a: String, /// It works with other attributes. #[rlp(default)] b: Option>, } - let attack_of = String::from("clones"); - let foo = Foo { a: attack_of.clone() }; + let attack_of = "clones"; + let item = Item { a: attack_of.into() }; let expected = vec![0xc7, 0x86, b'c', b'l', b'o', b'n', b'e', b's']; - let out = encode(&foo); + let out = encode(&item); assert_eq!(out, expected); - let foo_default = FooDefault { a: attack_of.clone(), b: None }; + let item_default = ItemDefault { a: attack_of.into(), b: None }; let decoded = decode(&expected).expect("default failure"); - assert_eq!(foo_default, decoded); + assert_eq!(item_default, decoded); - let foo_some = FooDefault { a: attack_of.clone(), b: Some(vec![1, 2, 3]) }; - let out = encode(&foo_some); - assert_eq!(decode(&out), Ok(foo_some)); + let item_some = ItemDefault { a: attack_of.into(), b: Some(vec![1, 2, 3]) }; + let out = encode(&item_some); + assert_eq!(decode(&out), Ok(item_some)); } From 05d7da889cb19b19f6a14c0c100341044695a72b Mon Sep 17 00:00:00 2001 From: Valentin Kettner Date: Fri, 21 Feb 2020 17:40:28 +0100 Subject: [PATCH 27/56] Implement Error for FromDecStrErr (#346) * Implement Error for FromDecStrErr * Only implement Error with std feature --- uint/src/uint.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/uint/src/uint.rs b/uint/src/uint.rs index ac0ffc85e..493e2e21e 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -38,6 +38,23 @@ pub enum FromDecStrErr { InvalidLength, } +#[cfg(feature = "std")] +impl std::fmt::Display for FromDecStrErr { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + FromDecStrErr::InvalidCharacter => "a character is not in the range 0-9", + FromDecStrErr::InvalidLength => "the number is too large for the type", + } + ) + } +} + +#[cfg(feature = "std")] +impl std::error::Error for FromDecStrErr {} + #[macro_export] #[doc(hidden)] macro_rules! impl_map_from { From 68dadf26c3b62a805c3e2a4b51f1de3880d24de5 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Thu, 27 Feb 2020 20:23:32 +0100 Subject: [PATCH 28/56] kvdb-rocksdb: expose RocksDB stats (#347) * kvdb-rocksdb: get_statistics method * kvdb-rocksdb: parse statistics string into a rust type * kvdb-rocksdb: integrate rocksdb block cache hit with kvdb::IoStats * kvdb-rocksdb: fmt * kvdb-rocksdb: add a test for stats parser * kvdb-rocksdb: hide rocksdb stats behind a config flag * kvdb-rocksdb: update changelog * Update kvdb-rocksdb/src/lib.rs Co-Authored-By: Nikolay Volf Co-authored-by: Nikolay Volf --- kvdb-rocksdb/CHANGELOG.md | 1 + kvdb-rocksdb/src/lib.rs | 57 ++++++++++++++++++++++++++++++-- kvdb-rocksdb/src/stats.rs | 68 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 118 insertions(+), 8 deletions(-) diff --git a/kvdb-rocksdb/CHANGELOG.md b/kvdb-rocksdb/CHANGELOG.md index dbebb5087..da022f21a 100644 --- a/kvdb-rocksdb/CHANGELOG.md +++ b/kvdb-rocksdb/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog]. ## [Unreleased] - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) +- Added `get_statistics` method and `enable_statistics` config parameter. [#347](https://github.com/paritytech/parity-common/pull/347) ## [0.5.0] - 2019-02-05 - Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index 42ee1388c..ac8958919 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -167,6 +167,12 @@ pub struct DatabaseConfig { pub columns: u32, /// Specify the maximum number of info/debug log files to be kept. pub keep_log_file_num: i32, + /// Enable native RocksDB statistics. + /// Disabled by default. + /// + /// It can have a negative performance impact up to 10% according to + /// https://github.com/facebook/rocksdb/wiki/Statistics. + pub enable_statistics: bool, } impl DatabaseConfig { @@ -215,6 +221,7 @@ impl Default for DatabaseConfig { compaction: CompactionProfile::default(), columns: 1, keep_log_file_num: 1, + enable_statistics: false, } } } @@ -267,6 +274,8 @@ pub struct Database { config: DatabaseConfig, path: String, #[ignore_malloc_size_of = "insignificant"] + opts: Options, + #[ignore_malloc_size_of = "insignificant"] write_opts: WriteOptions, #[ignore_malloc_size_of = "insignificant"] read_opts: ReadOptions, @@ -304,6 +313,10 @@ fn is_corrupted(err: &Error) -> bool { fn generate_options(config: &DatabaseConfig) -> Options { let mut opts = Options::default(); + opts.set_report_bg_io_stats(true); + if config.enable_statistics { + opts.enable_statistics(); + } opts.set_use_fsync(false); opts.create_if_missing(true); opts.set_max_open_files(config.max_open_files); @@ -409,6 +422,7 @@ impl Database { flushing: RwLock::new((0..config.columns).map(|_| HashMap::new()).collect()), flushing_lock: Mutex::new(false), path: path.to_owned(), + opts, read_opts, write_opts, block_opts, @@ -715,6 +729,15 @@ impl Database { None => Ok(()), } } + + /// Get RocksDB statistics. + pub fn get_statistics(&self) -> HashMap { + if let Some(stats) = self.opts.get_statistics() { + stats::parse_rocksdb_stats(&stats) + } else { + HashMap::new() + } + } } // duplicate declaration of methods here to avoid trait import in certain existing cases @@ -755,6 +778,13 @@ impl KeyValueDB for Database { } fn io_stats(&self, kind: kvdb::IoStatsKind) -> kvdb::IoStats { + let rocksdb_stats = self.get_statistics(); + let cache_hit_count = rocksdb_stats.get("block.cache.hit").map(|s| s.count).unwrap_or(0u64); + let overall_stats = self.stats.overall(); + let old_cache_hit_count = overall_stats.raw.cache_hit_count; + + self.stats.tally_cache_hit_count(cache_hit_count - old_cache_hit_count); + let taken_stats = match kind { kvdb::IoStatsKind::Overall => self.stats.overall(), kvdb::IoStatsKind::SincePrevious => self.stats.since_previous(), @@ -767,7 +797,7 @@ impl KeyValueDB for Database { stats.transactions = taken_stats.raw.transactions; stats.bytes_written = taken_stats.raw.bytes_written; stats.bytes_read = taken_stats.raw.bytes_read; - + stats.cache_reads = taken_stats.raw.cache_hit_count; stats.started = taken_stats.started; stats.span = taken_stats.started.elapsed(); @@ -847,6 +877,7 @@ mod tests { compaction: CompactionProfile::default(), columns: 11, keep_log_file_num: 1, + enable_statistics: false, }; let db = Database::open(&config, tempdir.path().to_str().unwrap()).unwrap(); @@ -984,20 +1015,40 @@ mod tests { assert_eq!(c.memory_budget(), 45 * MB, "total budget is the sum of the column budget"); } + #[test] + fn test_stats_parser() { + let raw = r#"rocksdb.row.cache.hit COUNT : 1 +rocksdb.db.get.micros P50 : 2.000000 P95 : 3.000000 P99 : 4.000000 P100 : 5.000000 COUNT : 0 SUM : 15 +"#; + let stats = stats::parse_rocksdb_stats(raw); + assert_eq!(stats["row.cache.hit"].count, 1); + assert!(stats["row.cache.hit"].times.is_none()); + assert_eq!(stats["db.get.micros"].count, 0); + let get_times = stats["db.get.micros"].times.unwrap(); + assert_eq!(get_times.sum, 15); + assert_eq!(get_times.p50, 2.0); + assert_eq!(get_times.p95, 3.0); + assert_eq!(get_times.p99, 4.0); + assert_eq!(get_times.p100, 5.0); + } + #[test] fn rocksdb_settings() { const NUM_COLS: usize = 2; - let mut cfg = DatabaseConfig::with_columns(NUM_COLS as u32); + let mut cfg = DatabaseConfig { enable_statistics: true, ..DatabaseConfig::with_columns(NUM_COLS as u32) }; cfg.max_open_files = 123; // is capped by the OS fd limit (typically 1024) cfg.compaction.block_size = 323232; cfg.compaction.initial_file_size = 102030; cfg.memory_budget = [(0, 30), (1, 300)].iter().cloned().collect(); let db_path = TempDir::new("config_test").expect("the OS can create tmp dirs"); - let _db = Database::open(&cfg, db_path.path().to_str().unwrap()).expect("can open a db"); + let db = Database::open(&cfg, db_path.path().to_str().unwrap()).expect("can open a db"); let mut rocksdb_log = std::fs::File::open(format!("{}/LOG", db_path.path().to_str().unwrap())) .expect("rocksdb creates a LOG file"); let mut settings = String::new(); + let statistics = db.get_statistics(); + assert!(statistics.contains_key("block.cache.hit")); + rocksdb_log.read_to_string(&mut settings).unwrap(); // Check column count assert!(settings.contains("Options for column family [default]"), "no default col"); diff --git a/kvdb-rocksdb/src/stats.rs b/kvdb-rocksdb/src/stats.rs index 80fa85ce2..c028b1948 100644 --- a/kvdb-rocksdb/src/stats.rs +++ b/kvdb-rocksdb/src/stats.rs @@ -7,15 +7,68 @@ // except according to those terms. use parking_lot::RwLock; +use std::collections::HashMap; +use std::str::FromStr; use std::sync::atomic::{AtomicU64, Ordering as AtomicOrdering}; use std::time::Instant; +#[derive(Default, Clone, Copy)] pub struct RawDbStats { pub reads: u64, pub writes: u64, pub bytes_written: u64, pub bytes_read: u64, pub transactions: u64, + pub cache_hit_count: u64, +} + +#[derive(Default, Debug, Clone, Copy)] +pub struct RocksDbStatsTimeValue { + /// 50% percentile + pub p50: f64, + /// 95% percentile + pub p95: f64, + /// 99% percentile + pub p99: f64, + /// 100% percentile + pub p100: f64, + pub sum: u64, +} + +#[derive(Default, Debug, Clone, Copy)] +pub struct RocksDbStatsValue { + pub count: u64, + pub times: Option, +} + +pub fn parse_rocksdb_stats(stats: &str) -> HashMap { + stats.lines().map(|line| parse_rocksdb_stats_row(line.splitn(2, ' '))).collect() +} + +fn parse_rocksdb_stats_row<'a>(mut iter: impl Iterator) -> (String, RocksDbStatsValue) { + const PROOF: &str = "rocksdb statistics format is valid and hasn't changed"; + const SEPARATOR: &str = " : "; + let key = iter.next().expect(PROOF).trim_start_matches("rocksdb.").to_owned(); + let values = iter.next().expect(PROOF); + let value = if values.starts_with("COUNT") { + // rocksdb.row.cache.hit COUNT : 0 + RocksDbStatsValue { + count: u64::from_str(values.rsplit(SEPARATOR).next().expect(PROOF)).expect(PROOF), + times: None, + } + } else { + // rocksdb.db.get.micros P50 : 0.000000 P95 : 0.000000 P99 : 0.000000 P100 : 0.000000 COUNT : 0 SUM : 0 + let values: Vec<&str> = values.split_whitespace().filter(|s| *s != ":").collect(); + let times = RocksDbStatsTimeValue { + p50: f64::from_str(values.get(1).expect(PROOF)).expect(PROOF), + p95: f64::from_str(values.get(3).expect(PROOF)).expect(PROOF), + p99: f64::from_str(values.get(5).expect(PROOF)).expect(PROOF), + p100: f64::from_str(values.get(7).expect(PROOF)).expect(PROOF), + sum: u64::from_str(values.get(11).expect(PROOF)).expect(PROOF), + }; + RocksDbStatsValue { count: u64::from_str(values.get(9).expect(PROOF)).expect(PROOF), times: Some(times) } + }; + (key, value) } impl RawDbStats { @@ -26,6 +79,7 @@ impl RawDbStats { bytes_written: self.bytes_written + other.bytes_written, bytes_read: self.bytes_read + other.bytes_written, transactions: self.transactions + other.transactions, + cache_hit_count: self.cache_hit_count + other.cache_hit_count, } } } @@ -38,11 +92,7 @@ struct OverallDbStats { impl OverallDbStats { fn new() -> Self { - OverallDbStats { - stats: RawDbStats { reads: 0, writes: 0, bytes_written: 0, bytes_read: 0, transactions: 0 }, - last_taken: Instant::now(), - started: Instant::now(), - } + OverallDbStats { stats: RawDbStats::default(), last_taken: Instant::now(), started: Instant::now() } } } @@ -52,6 +102,7 @@ pub struct RunningDbStats { bytes_written: AtomicU64, bytes_read: AtomicU64, transactions: AtomicU64, + cache_hit_count: AtomicU64, overall: RwLock, } @@ -68,6 +119,7 @@ impl RunningDbStats { writes: 0.into(), bytes_written: 0.into(), transactions: 0.into(), + cache_hit_count: 0.into(), overall: OverallDbStats::new().into(), } } @@ -92,6 +144,10 @@ impl RunningDbStats { self.transactions.fetch_add(val, AtomicOrdering::Relaxed); } + pub fn tally_cache_hit_count(&self, val: u64) { + self.cache_hit_count.fetch_add(val, AtomicOrdering::Relaxed); + } + fn take_current(&self) -> RawDbStats { RawDbStats { reads: self.reads.swap(0, AtomicOrdering::Relaxed), @@ -99,6 +155,7 @@ impl RunningDbStats { bytes_written: self.bytes_written.swap(0, AtomicOrdering::Relaxed), bytes_read: self.bytes_read.swap(0, AtomicOrdering::Relaxed), transactions: self.transactions.swap(0, AtomicOrdering::Relaxed), + cache_hit_count: self.cache_hit_count.swap(0, AtomicOrdering::Relaxed), } } @@ -109,6 +166,7 @@ impl RunningDbStats { bytes_written: self.bytes_written.load(AtomicOrdering::Relaxed), bytes_read: self.bytes_read.load(AtomicOrdering::Relaxed), transactions: self.transactions.load(AtomicOrdering::Relaxed), + cache_hit_count: self.cache_hit_count.load(AtomicOrdering::Relaxed), } } From 01ccef7b5a4f48af0f2cbdca1e7896ff5e0508f5 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 28 Feb 2020 17:01:35 +0100 Subject: [PATCH 29/56] kvdb-rocksdb: bump version (#348) --- kvdb-rocksdb/CHANGELOG.md | 2 ++ kvdb-rocksdb/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/kvdb-rocksdb/CHANGELOG.md b/kvdb-rocksdb/CHANGELOG.md index da022f21a..840e60b2f 100644 --- a/kvdb-rocksdb/CHANGELOG.md +++ b/kvdb-rocksdb/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.6.0] - 2019-02-28 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) - Added `get_statistics` method and `enable_statistics` config parameter. [#347](https://github.com/paritytech/parity-common/pull/347) diff --git a/kvdb-rocksdb/Cargo.toml b/kvdb-rocksdb/Cargo.toml index 1a51844e9..bfd75a14d 100644 --- a/kvdb-rocksdb/Cargo.toml +++ b/kvdb-rocksdb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kvdb-rocksdb" -version = "0.5.0" +version = "0.6.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "kvdb implementation backed by RocksDB" From 7ca53fb5320b639dbcfd75ada667ffde488fe219 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Thu, 12 Mar 2020 23:39:59 +0100 Subject: [PATCH 30/56] CI: troubleshoot macOS build (#356) --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bea20cf75..f52e084c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,12 +15,12 @@ matrix: script: - cargo check --all --benches - os: osx - osx_image: xcode11.2 + osx_image: xcode11.3 addons: chrome: stable firefox: latest install: - - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | sh + - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | sh - source ~/.nvm/nvm.sh - nvm install --lts - npm install -g chromedriver From 2f3167d10e8b55e1555ac73a467d2a1eb0d0fc02 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 13 Mar 2020 00:02:27 +0100 Subject: [PATCH 31/56] parity-util-mem: use malloc for usable_size on android (#355) --- parity-util-mem/src/allocators.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parity-util-mem/src/allocators.rs b/parity-util-mem/src/allocators.rs index e159a32d0..45df9cba2 100644 --- a/parity-util-mem/src/allocators.rs +++ b/parity-util-mem/src/allocators.rs @@ -96,7 +96,7 @@ mod usable_size { mimalloc_sys::mi_usable_size(ptr as *mut _) } - } else if #[cfg(target_os = "linux")] { + } else if #[cfg(any(target_os = "linux", target_os = "android"))] { /// Linux call system allocator (currently malloc). extern "C" { From c31dabe5c2b6fdb87963deece2331a24e9982c8f Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 13 Mar 2020 09:51:47 +0100 Subject: [PATCH 32/56] kvdb: remove parity-bytes dependency (#351) * kvdb: remove parity-bytes dependency * kvdb: update changelog * Update kvdb/CHANGELOG.md --- kvdb/CHANGELOG.md | 1 + kvdb/Cargo.toml | 1 - kvdb/src/lib.rs | 3 +-- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/kvdb/CHANGELOG.md b/kvdb/CHANGELOG.md index c7d38231b..d1e24ebb3 100644 --- a/kvdb/CHANGELOG.md +++ b/kvdb/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog]. ## [Unreleased] - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) +- Remove dependency on parity-bytes. [#351](https://github.com/paritytech/parity-common/pull/351) ## [0.4.0] - 2019-01-06 - Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) diff --git a/kvdb/Cargo.toml b/kvdb/Cargo.toml index c955920a9..722ebcc20 100644 --- a/kvdb/Cargo.toml +++ b/kvdb/Cargo.toml @@ -9,5 +9,4 @@ edition = "2018" [dependencies] smallvec = "1.0.0" -bytes = { package = "parity-bytes", version = "0.1", path = "../parity-bytes" } parity-util-mem = { path = "../parity-util-mem", version = "0.5", default-features = false } diff --git a/kvdb/src/lib.rs b/kvdb/src/lib.rs index 6382145ce..723714de5 100644 --- a/kvdb/src/lib.rs +++ b/kvdb/src/lib.rs @@ -8,7 +8,6 @@ //! Key-Value store abstraction. -use bytes::Bytes; use smallvec::SmallVec; use std::io; @@ -73,7 +72,7 @@ impl DBTransaction { } /// Insert a key-value pair in the transaction. Any existing value will be overwritten upon write. - pub fn put_vec(&mut self, col: u32, key: &[u8], value: Bytes) { + pub fn put_vec(&mut self, col: u32, key: &[u8], value: Vec) { self.ops.push(DBOp::Insert { col, key: DBKey::from_slice(key), value }); } From be0704968b15b01a05abf62a5492018c7b5d7fae Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 13 Mar 2020 10:44:14 +0100 Subject: [PATCH 33/56] parity-util-mem: update mimalloc feature (#352) * parity-util-mem: update mimalloc feature * parity-util-mem: enable 'secure' feature of mimalloc --- parity-util-mem/Cargo.toml | 11 +++-------- parity-util-mem/src/allocators.rs | 2 +- parity-util-mem/src/lib.rs | 10 +++++----- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index e0539b23c..7b097f7e8 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -13,13 +13,8 @@ dlmalloc = { version = "0.1.3", features = ["global"], optional = true } wee_alloc = { version = "0.4.5", optional = true } lru = { version = "0.4", optional = true } hashbrown = { version = "0.6", optional = true } -# from https://github.com/microsoft/mimalloc: -# mimalloc can be built in secure mode, -# adding guard pages, randomized allocation, encrypted free lists, etc. -# to protect against various heap vulnerabilities. -# The performance penalty is only around 3% on average over our benchmarks. -mimallocator = { version = "0.1.3", features = ["secure"], optional = true } -mimalloc-sys = { version = "0.1.6", optional = true } +mimalloc = { version = "0.1.18", optional = true } +libmimalloc-sys = { version = "0.1.14", optional = true } parity-util-mem-derive = { path = "derive", version = "0.1" } impl-trait-for-tuples = "0.1.3" @@ -45,7 +40,7 @@ weealloc-global = ["wee_alloc", "estimate-heapsize"] # use jemalloc as global allocator jemalloc-global = ["jemallocator"] # use mimalloc as global allocator -mimalloc-global = ["mimallocator", "mimalloc-sys"] +mimalloc-global = ["mimalloc", "libmimalloc-sys"] # implement additional types ethereum-impls = ["ethereum-types", "primitive-types"] # Full estimate: no call to allocator diff --git a/parity-util-mem/src/allocators.rs b/parity-util-mem/src/allocators.rs index 45df9cba2..8d8bb18db 100644 --- a/parity-util-mem/src/allocators.rs +++ b/parity-util-mem/src/allocators.rs @@ -93,7 +93,7 @@ mod usable_size { pub unsafe extern "C" fn malloc_usable_size(ptr: *const c_void) -> usize { // mimalloc doesn't actually mutate the value ptr points to, // but requires a mut pointer in the API - mimalloc_sys::mi_usable_size(ptr as *mut _) + libmimalloc_sys::mi_usable_size(ptr as *mut _) } } else if #[cfg(any(target_os = "linux", target_os = "android"))] { diff --git a/parity-util-mem/src/lib.rs b/parity-util-mem/src/lib.rs index 87b47716a..528f0f668 100644 --- a/parity-util-mem/src/lib.rs +++ b/parity-util-mem/src/lib.rs @@ -21,24 +21,24 @@ cfg_if::cfg_if! { not(target_os = "windows"), not(target_arch = "wasm32") ))] { - #[global_allocator] /// Global allocator + #[global_allocator] pub static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; } else if #[cfg(feature = "dlmalloc-global")] { - #[global_allocator] /// Global allocator + #[global_allocator] pub static ALLOC: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc; } else if #[cfg(feature = "weealloc-global")] { - #[global_allocator] /// Global allocator + #[global_allocator] pub static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; } else if #[cfg(all( feature = "mimalloc-global", not(target_arch = "wasm32") ))] { - #[global_allocator] /// Global allocator - pub static ALLOC: mimallocator::Mimalloc = mimallocator::Mimalloc; + #[global_allocator] + pub static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc; } else { // default allocator used } From 2cb0588dfa5ed81d1212ec1703df99132fb80deb Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 13 Mar 2020 15:06:23 +0100 Subject: [PATCH 34/56] travis: test parity-util-mem on android (#358) --- .travis.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index f52e084c2..19c6b18ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,12 +8,16 @@ matrix: rust: stable before_script: - rustup component add rustfmt - - os: linux - rust: beta - os: linux rust: nightly script: - - cargo check --all --benches + - cargo check --workspace --benches + - os: linux + rust: stable + install: + - cargo install cross + script: + - cross test --target=aarch64-linux-android -p parity-util-mem - os: osx osx_image: xcode11.3 addons: @@ -32,12 +36,10 @@ matrix: install: - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh script: - - if [ "$TRAVIS_RUST_VERSION" == "stable" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then + - if [ "$TRAVIS_OS_NAME" == "linux" ]; then cargo fmt -- --check; fi - - cargo check --all --tests - - cargo check --all --benches - - cargo build --all + - cargo check --workspace --tests --benches - cargo test --all --exclude uint --exclude fixed-hash --exclude parity-crypto - if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cd contract-address/ && cargo test --features=external_doc && cd ..; From bf5879459ade112d128312408d1f190f3839a93b Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 13 Mar 2020 23:03:26 +0100 Subject: [PATCH 35/56] parity-util-mem: prepare release for 0.5.2 (#359) --- parity-util-mem/CHANGELOG.md | 4 ++++ parity-util-mem/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/parity-util-mem/CHANGELOG.md b/parity-util-mem/CHANGELOG.md index dbab86b6e..211d42145 100644 --- a/parity-util-mem/CHANGELOG.md +++ b/parity-util-mem/CHANGELOG.md @@ -5,7 +5,11 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.5.2] - 2019-03-13 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) +- Updated mimalloc dependency. [#352](https://github.com/paritytech/parity-common/pull/352) +- Use malloc for `usable_size` on Android. [#355](https://github.com/paritytech/parity-common/pull/355) ## [0.5.1] - 2019-02-05 - Add different mode for malloc_size_of_is_0 macro dealing with generics. [#334](https://github.com/paritytech/parity-common/pull/334) diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index 7b097f7e8..96b1f2508 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parity-util-mem" -version = "0.5.1" +version = "0.5.2" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Collection of memory related utilities" From 32f8d96f051195197c3e6a266531690fd4e6ef20 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 16 Mar 2020 19:56:57 +0100 Subject: [PATCH 36/56] Prep for release (#361) * Prep for release * Removing a feature is a breaking change * Update ethereum-types/CHANGELOG.md Co-Authored-By: Andronik Ordian * Update keccak-hash/CHANGELOG.md Co-Authored-By: Andronik Ordian * Update parity-util-mem/CHANGELOG.md Co-Authored-By: Andronik Ordian * Update rlp/CHANGELOG.md Co-Authored-By: Andronik Ordian * Breaking where breaking is due Co-authored-by: Andronik Ordian --- contract-address/CHANGELOG.md | 3 +++ contract-address/Cargo.toml | 6 +++--- ethbloom/CHANGELOG.md | 2 ++ ethbloom/Cargo.toml | 4 ++-- ethereum-types/CHANGELOG.md | 3 +++ ethereum-types/Cargo.toml | 8 ++++---- fixed-hash/CHANGELOG.md | 2 ++ fixed-hash/Cargo.toml | 2 +- keccak-hash/CHANGELOG.md | 3 +++ keccak-hash/Cargo.toml | 4 ++-- kvdb-memorydb/CHANGELOG.md | 3 +++ kvdb-memorydb/Cargo.toml | 6 +++--- kvdb-rocksdb/CHANGELOG.md | 5 ++++- kvdb-rocksdb/Cargo.toml | 6 +++--- kvdb-shared-tests/Cargo.toml | 2 +- kvdb-web/CHANGELOG.md | 3 +++ kvdb-web/Cargo.toml | 8 ++++---- kvdb/CHANGELOG.md | 3 +++ kvdb/Cargo.toml | 4 ++-- parity-bytes/CHANGELOG.md | 2 ++ parity-bytes/Cargo.toml | 2 +- parity-crypto/CHANGELOG.md | 3 +++ parity-crypto/Cargo.toml | 24 ++++++++++++------------ parity-path/CHANGELOG.md | 2 ++ parity-path/Cargo.toml | 2 +- parity-util-mem/CHANGELOG.md | 5 ++++- parity-util-mem/Cargo.toml | 6 +++--- plain_hasher/CHANGELOG.md | 2 ++ plain_hasher/Cargo.toml | 2 +- primitive-types/CHANGELOG.md | 2 ++ primitive-types/Cargo.toml | 4 ++-- rlp/CHANGELOG.md | 4 ++++ rlp/Cargo.toml | 4 ++-- trace-time/CHANGELOG.md | 2 ++ trace-time/Cargo.toml | 2 +- transaction-pool/CHANGELOG.md | 2 ++ transaction-pool/Cargo.toml | 4 ++-- triehash/CHANGELOG.md | 3 ++- triehash/Cargo.toml | 4 ++-- 39 files changed, 103 insertions(+), 55 deletions(-) diff --git a/contract-address/CHANGELOG.md b/contract-address/CHANGELOG.md index 546bc458e..a9b2a3a0b 100644 --- a/contract-address/CHANGELOG.md +++ b/contract-address/CHANGELOG.md @@ -5,4 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.9.0] - 2020-03-16 - License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) +- Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) diff --git a/contract-address/Cargo.toml b/contract-address/Cargo.toml index 21486e7a2..19ee6b363 100644 --- a/contract-address/Cargo.toml +++ b/contract-address/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "contract-address" -version = "0.3.0" +version = "0.4.0" authors = ["Parity Technologies "] license = "MIT/Apache2.0" homepage = "https://github.com/paritytech/parity-common" @@ -11,9 +11,9 @@ edition = "2018" readme = "README.md" [dependencies] -ethereum-types = { version = "0.8.0", path = "../ethereum-types" } +ethereum-types = { version = "0.9.0", path = "../ethereum-types" } rlp = { version = "0.4", path = "../rlp" } -keccak-hash = { version = "0.4", path = "../keccak-hash", default-features = false } +keccak-hash = { version = "0.5", path = "../keccak-hash", default-features = false } [features] default = [] diff --git a/ethbloom/CHANGELOG.md b/ethbloom/CHANGELOG.md index 6c13f6f0a..de418cd9d 100644 --- a/ethbloom/CHANGELOG.md +++ b/ethbloom/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.9.0] - 2020-03-16 - Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) - License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index cbf9112a0..da4b20047 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ethbloom" -version = "0.8.1" +version = "0.9.0" authors = ["Parity Technologies "] description = "Ethereum bloom filter" license = "MIT/Apache2.0" @@ -12,7 +12,7 @@ edition = "2018" [dependencies] tiny-keccak = { version = "2.0", features = ["keccak"] } crunchy = { version = "0.2.2", default-features = false, features = ["limit_256"] } -fixed-hash = { path = "../fixed-hash", version = "0.5", default-features = false } +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 } diff --git a/ethereum-types/CHANGELOG.md b/ethereum-types/CHANGELOG.md index 6b214e75b..9455e7bba 100644 --- a/ethereum-types/CHANGELOG.md +++ b/ethereum-types/CHANGELOG.md @@ -5,7 +5,10 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.9.0] - 2020-03-16 - License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) +- Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) ### Added - Uint error type is re-exported. [#244](https://github.com/paritytech/parity-common/pull/244) diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index b706f2873..00b49ac7a 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ethereum-types" -version = "0.8.0" +version = "0.9.0" authors = ["Parity Technologies "] license = "MIT/Apache2.0" homepage = "https://github.com/paritytech/parity-common" @@ -8,10 +8,10 @@ description = "Ethereum types" edition = "2018" [dependencies] -ethbloom = { path = "../ethbloom", version = "0.8", default-features = false } -fixed-hash = { path = "../fixed-hash", version = "0.5", default-features = false, features = ["byteorder", "rustc-hex"] } +ethbloom = { path = "../ethbloom", version = "0.9", default-features = false } +fixed-hash = { path = "../fixed-hash", version = "0.6", default-features = false, features = ["byteorder", "rustc-hex"] } uint-crate = { path = "../uint", package = "uint", version = "0.8", default-features = false } -primitive-types = { path = "../primitive-types", version = "0.6", features = ["rlp", "byteorder", "rustc-hex"], default-features = false } +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 } diff --git a/fixed-hash/CHANGELOG.md b/fixed-hash/CHANGELOG.md index f486d7847..da5ec524d 100644 --- a/fixed-hash/CHANGELOG.md +++ b/fixed-hash/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.6.0] - 2020-03-16 - Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) - License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) diff --git a/fixed-hash/Cargo.toml b/fixed-hash/Cargo.toml index 41bf7d237..324804592 100644 --- a/fixed-hash/Cargo.toml +++ b/fixed-hash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fixed-hash" -version = "0.5.2" +version = "0.6.0" authors = ["Parity Technologies "] license = "MIT/Apache2.0" homepage = "https://github.com/paritytech/parity-common" diff --git a/keccak-hash/CHANGELOG.md b/keccak-hash/CHANGELOG.md index 429e3bc13..13f73c4a9 100644 --- a/keccak-hash/CHANGELOG.md +++ b/keccak-hash/CHANGELOG.md @@ -5,7 +5,10 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.4.2] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) +- Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) ## [0.4.1] - 2019-10-24 ### Dependencies diff --git a/keccak-hash/Cargo.toml b/keccak-hash/Cargo.toml index 49c9506dd..ca317f522 100644 --- a/keccak-hash/Cargo.toml +++ b/keccak-hash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "keccak-hash" -version = "0.4.1" +version = "0.5.0" description = "`keccak-hash` is a set of utility functions to facilitate working with Keccak hashes (256/512 bits long)." authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" @@ -10,7 +10,7 @@ edition = "2018" [dependencies] tiny-keccak = { version = "2.0", features = ["keccak"] } -primitive-types = { path = "../primitive-types", version = "0.6", default-features = false } +primitive-types = { path = "../primitive-types", version = "0.7", default-features = false } [dev-dependencies] tempdir = "0.3.7" diff --git a/kvdb-memorydb/CHANGELOG.md b/kvdb-memorydb/CHANGELOG.md index 3da9b9203..a8c74772d 100644 --- a/kvdb-memorydb/CHANGELOG.md +++ b/kvdb-memorydb/CHANGELOG.md @@ -5,7 +5,10 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.5.0] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) +- Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) ## [0.4.0] - 2019-02-05 - Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) diff --git a/kvdb-memorydb/Cargo.toml b/kvdb-memorydb/Cargo.toml index 24d6a9991..90a5dc980 100644 --- a/kvdb-memorydb/Cargo.toml +++ b/kvdb-memorydb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kvdb-memorydb" -version = "0.4.0" +version = "0.5.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "A key-value in-memory database that implements the `KeyValueDB` trait" @@ -8,9 +8,9 @@ license = "MIT/Apache-2.0" edition = "2018" [dependencies] -parity-util-mem = { path = "../parity-util-mem", version = "0.5", default-features = false, features = ["std"] } +parity-util-mem = { path = "../parity-util-mem", version = "0.6", default-features = false, features = ["std"] } parking_lot = "0.10.0" -kvdb = { version = "0.4", path = "../kvdb" } +kvdb = { version = "0.5", path = "../kvdb" } [dev-dependencies] kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.2" } diff --git a/kvdb-rocksdb/CHANGELOG.md b/kvdb-rocksdb/CHANGELOG.md index 840e60b2f..e7561c059 100644 --- a/kvdb-rocksdb/CHANGELOG.md +++ b/kvdb-rocksdb/CHANGELOG.md @@ -6,7 +6,10 @@ The format is based on [Keep a Changelog]. ## [Unreleased] -## [0.6.0] - 2019-02-28 +## [0.7.0] - 2020-03-16 +- Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) + +## [0.6.0] - 2020-02-28 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) - Added `get_statistics` method and `enable_statistics` config parameter. [#347](https://github.com/paritytech/parity-common/pull/347) diff --git a/kvdb-rocksdb/Cargo.toml b/kvdb-rocksdb/Cargo.toml index bfd75a14d..c4d573bf8 100644 --- a/kvdb-rocksdb/Cargo.toml +++ b/kvdb-rocksdb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kvdb-rocksdb" -version = "0.6.0" +version = "0.7.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "kvdb implementation backed by RocksDB" @@ -15,14 +15,14 @@ harness = false smallvec = "1.0.0" fs-swap = "0.2.4" interleaved-ordered = "0.1.1" -kvdb = { path = "../kvdb", version = "0.4" } +kvdb = { path = "../kvdb", version = "0.5" } log = "0.4.8" num_cpus = "1.10.1" parking_lot = "0.10.0" regex = "1.3.1" rocksdb = { version = "0.13", features = ["snappy"], default-features = false } owning_ref = "0.4.0" -parity-util-mem = { path = "../parity-util-mem", version = "0.5", default-features = false, features = ["std", "smallvec"] } +parity-util-mem = { path = "../parity-util-mem", version = "0.6", default-features = false, features = ["std", "smallvec"] } [dev-dependencies] alloc_counter = "0.0.4" diff --git a/kvdb-shared-tests/Cargo.toml b/kvdb-shared-tests/Cargo.toml index 367eef8b6..ff461caac 100644 --- a/kvdb-shared-tests/Cargo.toml +++ b/kvdb-shared-tests/Cargo.toml @@ -7,4 +7,4 @@ description = "Shared tests for kvdb functionality, to be executed against actua license = "MIT/Apache2.0" [dependencies] -kvdb = { path = "../kvdb", version = "0.4" } +kvdb = { path = "../kvdb", version = "0.5" } diff --git a/kvdb-web/CHANGELOG.md b/kvdb-web/CHANGELOG.md index 0d4a23ad9..f8e952bf3 100644 --- a/kvdb-web/CHANGELOG.md +++ b/kvdb-web/CHANGELOG.md @@ -5,7 +5,10 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.5.0] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) +- Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) ## [0.4.0] - 2019-02-05 - Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) diff --git a/kvdb-web/Cargo.toml b/kvdb-web/Cargo.toml index 284418ca5..8d5fc7be4 100644 --- a/kvdb-web/Cargo.toml +++ b/kvdb-web/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kvdb-web" -version = "0.4.0" +version = "0.5.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "A key-value database for use in browsers" @@ -11,12 +11,12 @@ edition = "2018" [dependencies] wasm-bindgen = "0.2.54" js-sys = "0.3.31" -kvdb = { version = "0.4", path = "../kvdb" } -kvdb-memorydb = { version = "0.4", path = "../kvdb-memorydb" } +kvdb = { version = "0.5", path = "../kvdb" } +kvdb-memorydb = { version = "0.5", path = "../kvdb-memorydb" } futures = "0.3" log = "0.4.8" send_wrapper = "0.3.0" -parity-util-mem = { path = "../parity-util-mem", version = "0.5", default-features = false } +parity-util-mem = { path = "../parity-util-mem", version = "0.6", default-features = false } [dependencies.web-sys] version = "0.3.31" diff --git a/kvdb/CHANGELOG.md b/kvdb/CHANGELOG.md index d1e24ebb3..18f484117 100644 --- a/kvdb/CHANGELOG.md +++ b/kvdb/CHANGELOG.md @@ -5,8 +5,11 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.5.0] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) - Remove dependency on parity-bytes. [#351](https://github.com/paritytech/parity-common/pull/351) +- Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) ## [0.4.0] - 2019-01-06 - Bump parking_lot to 0.10. [#332](https://github.com/paritytech/parity-common/pull/332) diff --git a/kvdb/Cargo.toml b/kvdb/Cargo.toml index 722ebcc20..669b19762 100644 --- a/kvdb/Cargo.toml +++ b/kvdb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kvdb" -version = "0.4.0" +version = "0.5.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Generic key-value trait" @@ -9,4 +9,4 @@ edition = "2018" [dependencies] smallvec = "1.0.0" -parity-util-mem = { path = "../parity-util-mem", version = "0.5", default-features = false } +parity-util-mem = { path = "../parity-util-mem", version = "0.6", default-features = false } diff --git a/parity-bytes/CHANGELOG.md b/parity-bytes/CHANGELOG.md index ef8a2633d..49b2d0857 100644 --- a/parity-bytes/CHANGELOG.md +++ b/parity-bytes/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.1.2] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.1.1] - 2019-10-24 diff --git a/parity-bytes/Cargo.toml b/parity-bytes/Cargo.toml index 582d6560e..384489203 100644 --- a/parity-bytes/Cargo.toml +++ b/parity-bytes/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parity-bytes" -version = "0.1.1" +version = "0.1.2" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "byte utilities for Parity" diff --git a/parity-crypto/CHANGELOG.md b/parity-crypto/CHANGELOG.md index c955084f9..14290d54d 100644 --- a/parity-crypto/CHANGELOG.md +++ b/parity-crypto/CHANGELOG.md @@ -5,7 +5,10 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.6.0] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) +- Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) ## [0.5.0] - 2020-02-08 - Remove `inv()` from `SecretKey` (breaking). [#258](https://github.com/paritytech/parity-common/pull/258) diff --git a/parity-crypto/Cargo.toml b/parity-crypto/Cargo.toml index 0af20678b..f51bbd88f 100644 --- a/parity-crypto/Cargo.toml +++ b/parity-crypto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parity-crypto" -version = "0.5.0" +version = "0.6.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Crypto utils used by ethstore and network." @@ -14,23 +14,23 @@ harness = false required-features = ["publickey"] [dependencies] -tiny-keccak = { version = "2.0", features = ["keccak"] } -scrypt = { version = "0.2.0", default-features = false } -secp256k1 = { version = "0.17.2", optional = true, features = ["recovery", "rand-std"] } -ethereum-types = { version = "0.8.0", optional = true } -lazy_static = { version = "1.0", optional = true } -ripemd160 = "0.8.0" -sha2 = "0.8.0" -digest = "0.8" -hmac = "0.7" aes = "0.3.2" aes-ctr = "0.3.0" block-modes = "0.3.3" +digest = "0.8" +ethereum-types = { version = "0.9.0", optional = true, path = "../ethereum-types" } +hmac = "0.7" +lazy_static = { version = "1.0", optional = true } pbkdf2 = "0.3.0" -subtle = "2.2.1" -zeroize = { version = "1.0.0", default-features = false } rand = "0.7.2" +ripemd160 = "0.8.0" rustc-hex = { version = "2.1.0", default-features = false, optional = true } +scrypt = { version = "0.2.0", default-features = false } +secp256k1 = { version = "0.17.2", optional = true, features = ["recovery", "rand-std"] } +sha2 = "0.8.0" +subtle = "2.2.1" +tiny-keccak = { version = "2.0", features = ["keccak"] } +zeroize = { version = "1.0.0", default-features = false } [dev-dependencies] criterion = "0.3.0" diff --git a/parity-path/CHANGELOG.md b/parity-path/CHANGELOG.md index fc0263835..ed9aa8162 100644 --- a/parity-path/CHANGELOG.md +++ b/parity-path/CHANGELOG.md @@ -5,4 +5,6 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.1.3] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) diff --git a/parity-path/Cargo.toml b/parity-path/Cargo.toml index 0c783cf6c..8f272ad51 100644 --- a/parity-path/Cargo.toml +++ b/parity-path/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parity-path" -version = "0.1.2" +version = "0.1.3" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Path utilities" diff --git a/parity-util-mem/CHANGELOG.md b/parity-util-mem/CHANGELOG.md index 211d42145..fdb3f5f7b 100644 --- a/parity-util-mem/CHANGELOG.md +++ b/parity-util-mem/CHANGELOG.md @@ -6,7 +6,10 @@ The format is based on [Keep a Changelog]. ## [Unreleased] -## [0.5.2] - 2019-03-13 +## [0.6.0] - 2020-03-13 +- Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) + +## [0.5.2] - 2020-03-13 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) - Updated mimalloc dependency. [#352](https://github.com/paritytech/parity-common/pull/352) - Use malloc for `usable_size` on Android. [#355](https://github.com/paritytech/parity-common/pull/355) diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index 96b1f2508..9f5e77039 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parity-util-mem" -version = "0.5.2" +version = "0.6.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Collection of memory related utilities" @@ -19,9 +19,9 @@ parity-util-mem-derive = { path = "derive", version = "0.1" } impl-trait-for-tuples = "0.1.3" smallvec = { version = "1.0.0", optional = true } -ethereum-types = { version = "0.8.0", optional = true, path = "../ethereum-types" } +ethereum-types = { version = "0.9.0", optional = true, path = "../ethereum-types" } parking_lot = { version = "0.10.0", optional = true } -primitive-types = { version = "0.6", path = "../primitive-types", default-features = false, optional = true } +primitive-types = { version = "0.7", path = "../primitive-types", default-features = false, optional = true } [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3.8", features = ["heapapi"] } diff --git a/plain_hasher/CHANGELOG.md b/plain_hasher/CHANGELOG.md index afc302090..c3f142cfd 100644 --- a/plain_hasher/CHANGELOG.md +++ b/plain_hasher/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.2.3] - 2020-03-16 - License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.2.2] - 2019-10-24 diff --git a/plain_hasher/Cargo.toml b/plain_hasher/Cargo.toml index 57cf4d0c1..7e0812571 100644 --- a/plain_hasher/Cargo.toml +++ b/plain_hasher/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "plain_hasher" description = "Hasher for 32-byte keys." -version = "0.2.2" +version = "0.2.3" authors = ["Parity Technologies "] license = "MIT/Apache2.0" keywords = ["hash", "hasher"] diff --git a/primitive-types/CHANGELOG.md b/primitive-types/CHANGELOG.md index 0689eab5a..4c6f65713 100644 --- a/primitive-types/CHANGELOG.md +++ b/primitive-types/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.7.0] - 2020-03-16 - Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) ## [0.6.2] - 2019-01-03 diff --git a/primitive-types/Cargo.toml b/primitive-types/Cargo.toml index e6b53391c..3169b5c2e 100644 --- a/primitive-types/Cargo.toml +++ b/primitive-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "primitive-types" -version = "0.6.2" +version = "0.7.0" authors = ["Parity Technologies "] license = "MIT/Apache2.0" homepage = "https://github.com/paritytech/parity-common" @@ -8,7 +8,7 @@ description = "Primitive types shared by Ethereum and Substrate" edition = "2018" [dependencies] -fixed-hash = { version = "0.5", path = "../fixed-hash", default-features = false } +fixed-hash = { version = "0.6", path = "../fixed-hash", default-features = false } uint = { version = "0.8.1", path = "../uint", default-features = false } impl-serde = { version = "0.3.0", path = "impls/serde", default-features = false, optional = true } impl-codec = { version = "0.4.1", path = "impls/codec", default-features = false, optional = true } diff --git a/rlp/CHANGELOG.md b/rlp/CHANGELOG.md index c817dc6b9..cee20902d 100644 --- a/rlp/CHANGELOG.md +++ b/rlp/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.4.5] - 2020-03-16 +### Dependencies +- Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) + ## [0.4.4] - 2019-11-20 ### Added - Method `Rlp::at_with_offset`. [#269](https://github.com/paritytech/parity-common/pull/269) diff --git a/rlp/Cargo.toml b/rlp/Cargo.toml index ea0da9b10..947418a6b 100644 --- a/rlp/Cargo.toml +++ b/rlp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rlp" -version = "0.4.4" +version = "0.4.5" description = "Recursive-length prefix encoding, decoding, and compression" repository = "https://github.com/paritytech/parity-common" license = "MIT/Apache-2.0" @@ -13,7 +13,7 @@ rustc-hex = { version = "2.0.1", default-features = false } [dev-dependencies] criterion = "0.3.0" hex-literal = "0.2.1" -primitive-types = { path = "../primitive-types", version = "0.6", features = ["impl-rlp"] } +primitive-types = { path = "../primitive-types", version = "0.7", features = ["impl-rlp"] } [features] default = ["std"] diff --git a/trace-time/CHANGELOG.md b/trace-time/CHANGELOG.md index 300ce6461..0f666b438 100644 --- a/trace-time/CHANGELOG.md +++ b/trace-time/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [0.1.3] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.1.2] - 2019-10-24 diff --git a/trace-time/Cargo.toml b/trace-time/Cargo.toml index fca5a7619..225cdec27 100644 --- a/trace-time/Cargo.toml +++ b/trace-time/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "trace-time" description = "Easily trace time to execute a scope." -version = "0.1.2" +version = "0.1.3" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" license = "MIT/Apache2.0" diff --git a/transaction-pool/CHANGELOG.md b/transaction-pool/CHANGELOG.md index 431effd94..334625f2d 100644 --- a/transaction-pool/CHANGELOG.md +++ b/transaction-pool/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] + +## [2.0.3] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [2.0.2] - 2019-10-24 diff --git a/transaction-pool/Cargo.toml b/transaction-pool/Cargo.toml index 0da12d924..2bf1dbb59 100644 --- a/transaction-pool/Cargo.toml +++ b/transaction-pool/Cargo.toml @@ -1,7 +1,7 @@ [package] description = "Generic transaction pool." name = "transaction-pool" -version = "2.0.2" +version = "2.0.3" license = "MIT/Apache2.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" @@ -13,4 +13,4 @@ smallvec = "0.6.10" trace-time = { path = "../trace-time", version = "0.1" } [dev-dependencies] -ethereum-types = { version = "0.8.0", path = "../ethereum-types" } +ethereum-types = { version = "0.9.0", path = "../ethereum-types" } diff --git a/triehash/CHANGELOG.md b/triehash/CHANGELOG.md index 88acd4dd1..b5f0357b1 100644 --- a/triehash/CHANGELOG.md +++ b/triehash/CHANGELOG.md @@ -5,8 +5,9 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] -- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) +## [0.8.3] - 2020-03-16 +- License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) ## [0.8.2] - 2019-12-15 - Added no-std support. [#280](https://github.com/paritytech/parity-common/pull/280) ## [0.8.1] - 2019-10-24 diff --git a/triehash/Cargo.toml b/triehash/Cargo.toml index 407489469..19496503a 100644 --- a/triehash/Cargo.toml +++ b/triehash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "triehash" -version = "0.8.2" +version = "0.8.3" authors = ["Parity Technologies "] description = "In-memory patricia trie operations" repository = "https://github.com/paritytech/parity-common" @@ -14,7 +14,7 @@ rlp = { version = "0.4", path = "../rlp", default-features = false } [dev-dependencies] criterion = "0.3.0" keccak-hasher = "0.15.2" -ethereum-types = { version = "0.8.0", path = "../ethereum-types" } +ethereum-types = { version = "0.9.0", path = "../ethereum-types" } tiny-keccak = { version = "2.0", features = ["keccak"] } trie-standardmap = "0.15.2" hex-literal = "0.2.1" From 939151e23b132110628739e8458e6cece1f1c8d0 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Tue, 17 Mar 2020 06:25:26 -0700 Subject: [PATCH 37/56] Memtest example for Rocksdb (#349) * memtest * address review * Update kvdb-rocksdb/examples/memtest.rs * return time 0.1 --- kvdb-rocksdb/Cargo.toml | 4 + kvdb-rocksdb/examples/memtest.rs | 149 +++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 kvdb-rocksdb/examples/memtest.rs diff --git a/kvdb-rocksdb/Cargo.toml b/kvdb-rocksdb/Cargo.toml index c4d573bf8..3204bbd79 100644 --- a/kvdb-rocksdb/Cargo.toml +++ b/kvdb-rocksdb/Cargo.toml @@ -31,3 +31,7 @@ ethereum-types = { path = "../ethereum-types" } kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.2" } rand = "0.7.2" tempdir = "0.3.7" +keccak-hash = { path = "../keccak-hash" } +sysinfo = "0.11.7" +ctrlc = "3.1.4" +time = "0.1" diff --git a/kvdb-rocksdb/examples/memtest.rs b/kvdb-rocksdb/examples/memtest.rs new file mode 100644 index 000000000..59fa1a137 --- /dev/null +++ b/kvdb-rocksdb/examples/memtest.rs @@ -0,0 +1,149 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Parity Ethereum. + +// Parity Ethereum is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity Ethereum is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity Ethereum. If not, see . + +// This program starts writing random data to the database with 100 (COLUMN_COUNT) +// columns and never stops until interrupted. + +use ethereum_types::H256; +use keccak_hash::keccak; +use kvdb_rocksdb::{Database, DatabaseConfig}; +use std::sync::{atomic::AtomicBool, atomic::Ordering as AtomicOrdering, Arc}; +use sysinfo::{get_current_pid, ProcessExt, System, SystemExt}; + +const COLUMN_COUNT: u32 = 100; + +#[derive(Clone)] +struct KeyValueSeed { + seed: H256, + key: H256, + val: H256, +} + +fn next(seed: H256) -> H256 { + let mut buf = [0u8; 33]; + buf[0..32].copy_from_slice(&seed[..]); + buf[32] = 1; + + keccak(&buf[..]) +} + +impl KeyValueSeed { + fn with_seed(seed: H256) -> Self { + KeyValueSeed { seed, key: next(seed), val: next(next(seed)) } + } + + fn new() -> Self { + Self::with_seed(H256::random()) + } +} + +impl Iterator for KeyValueSeed { + type Item = (H256, H256); + + fn next(&mut self) -> Option { + let result = (self.key, self.val); + self.key = next(self.val); + self.val = next(self.key); + + Some(result) + } +} + +fn proc_memory_usage() -> u64 { + let mut sys = System::new(); + let self_pid = get_current_pid().ok(); + let memory = if let Some(self_pid) = self_pid { + if sys.refresh_process(self_pid) { + let proc = sys.get_process(self_pid).expect("Above refresh_process succeeds, this should be Some(), qed"); + proc.memory() + } else { + 0 + } + } else { + 0 + }; + + memory +} + +fn main() { + let mb_per_col = std::env::args() + .nth(1) + .map(|arg| arg.parse().expect("Megabytes per col - should be integer or missing")) + .unwrap_or(1); + + let exit = Arc::new(AtomicBool::new(false)); + let ctrlc_exit = exit.clone(); + + ctrlc::set_handler(move || { + println!("\nRemoving temp database...\n"); + ctrlc_exit.store(true, AtomicOrdering::Relaxed); + }) + .expect("Error setting Ctrl-C handler"); + + let mut config = DatabaseConfig::with_columns(COLUMN_COUNT); + + for c in 0..=COLUMN_COUNT { + config.memory_budget.insert(c, mb_per_col); + } + let dir = tempdir::TempDir::new("rocksdb-example").unwrap(); + + println!("Database is put in: {} (maybe check if it was deleted)", dir.path().to_string_lossy()); + let db = Database::open(&config, &dir.path().to_string_lossy()).unwrap(); + + let mut step = 0; + let mut keyvalues = KeyValueSeed::new(); + while !exit.load(AtomicOrdering::Relaxed) { + let col = step % 100; + + let key_values: Vec<(H256, H256)> = keyvalues.clone().take(128).collect(); + let mut transaction = db.transaction(); + for (k, v) in key_values.iter() { + transaction.put(col, k.as_ref(), v.as_ref()); + } + db.write(transaction).expect("writing failed"); + + let mut seed = H256::zero(); + for (k, _) in key_values.iter() { + let mut buf = [0u8; 64]; + buf[0..32].copy_from_slice(seed.as_ref()); + let val = db.get(col, k.as_ref()).expect("Db fail").expect("Was put above"); + buf[32..64].copy_from_slice(val.as_ref()); + + seed = keccak(&buf[..]); + } + + let mut transaction = db.transaction(); + // delete all but one to avoid too much bloating + for (k, _) in key_values.iter().take(127) { + transaction.delete(col, k.as_ref()); + } + db.write(transaction).expect("delete failed"); + + keyvalues = KeyValueSeed::with_seed(seed); + + if step % 10000 == 9999 { + let timestamp = time::strftime("%Y-%m-%d %H:%M:%S", &time::now()).expect("Error formatting log timestamp"); + + println!("{}", timestamp); + println!("\tData written: {} keys - {} Mb", step + 1, ((step + 1) * 64 * 128) / 1024 / 1024); + println!("\tProcess memory used as seen by the OS: {} Mb", proc_memory_usage() / 1024); + println!("\tMemory used as reported by rocksdb: {} Mb\n", parity_util_mem::malloc_size(&db) / 1024 / 1024); + } + + step += 1; + } +} From 791f5524da0de25a061fa1c71164b036af43e172 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 25 Mar 2020 09:45:49 +0100 Subject: [PATCH 38/56] Use correct license ID (#362) * Use correct license ID * SPDX format for license ID --- contract-address/Cargo.toml | 2 +- ethbloom/Cargo.toml | 2 +- ethereum-types/Cargo.toml | 2 +- fixed-hash/Cargo.toml | 2 +- keccak-hash/Cargo.toml | 2 +- kvdb-memorydb/Cargo.toml | 2 +- kvdb-rocksdb/Cargo.toml | 2 +- kvdb-shared-tests/Cargo.toml | 2 +- kvdb-web/Cargo.toml | 2 +- kvdb/Cargo.toml | 2 +- parity-bytes/Cargo.toml | 2 +- parity-crypto/Cargo.toml | 2 +- parity-path/Cargo.toml | 2 +- parity-util-mem/Cargo.toml | 2 +- parity-util-mem/derive/Cargo.toml | 2 +- plain_hasher/Cargo.toml | 2 +- primitive-types/Cargo.toml | 2 +- primitive-types/impls/codec/Cargo.toml | 2 +- primitive-types/impls/rlp/Cargo.toml | 2 +- primitive-types/impls/serde/Cargo.toml | 2 +- rlp-derive/Cargo.toml | 2 +- rlp/Cargo.toml | 2 +- trace-time/Cargo.toml | 2 +- transaction-pool/Cargo.toml | 2 +- triehash/Cargo.toml | 2 +- uint/Cargo.toml | 2 +- 26 files changed, 26 insertions(+), 26 deletions(-) diff --git a/contract-address/Cargo.toml b/contract-address/Cargo.toml index 19ee6b363..b8a0b7993 100644 --- a/contract-address/Cargo.toml +++ b/contract-address/Cargo.toml @@ -2,7 +2,7 @@ name = "contract-address" version = "0.4.0" authors = ["Parity Technologies "] -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" repository = "https://github.com/paritytech/parity-common" description = "A utility crate to create an ethereum contract address" diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index da4b20047..038378a64 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -3,7 +3,7 @@ name = "ethbloom" version = "0.9.0" authors = ["Parity Technologies "] description = "Ethereum bloom filter" -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" documentation = "https://docs.rs/ethbloom" homepage = "https://github.com/paritytech/parity-common" repository = "https://github.com/paritytech/parity-common" diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index 00b49ac7a..b04c87bbd 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -2,7 +2,7 @@ name = "ethereum-types" version = "0.9.0" authors = ["Parity Technologies "] -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" description = "Ethereum types" edition = "2018" diff --git a/fixed-hash/Cargo.toml b/fixed-hash/Cargo.toml index 324804592..93903ef7d 100644 --- a/fixed-hash/Cargo.toml +++ b/fixed-hash/Cargo.toml @@ -2,7 +2,7 @@ name = "fixed-hash" version = "0.6.0" authors = ["Parity Technologies "] -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" repository = "https://github.com/paritytech/parity-common" description = "Macros to define custom fixed-size hash types" diff --git a/keccak-hash/Cargo.toml b/keccak-hash/Cargo.toml index ca317f522..ea36f7288 100644 --- a/keccak-hash/Cargo.toml +++ b/keccak-hash/Cargo.toml @@ -5,7 +5,7 @@ description = "`keccak-hash` is a set of utility functions to facilitate working authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" readme = "README.md" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [dependencies] diff --git a/kvdb-memorydb/Cargo.toml b/kvdb-memorydb/Cargo.toml index 90a5dc980..0ea7119a8 100644 --- a/kvdb-memorydb/Cargo.toml +++ b/kvdb-memorydb/Cargo.toml @@ -4,7 +4,7 @@ version = "0.5.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "A key-value in-memory database that implements the `KeyValueDB` trait" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [dependencies] diff --git a/kvdb-rocksdb/Cargo.toml b/kvdb-rocksdb/Cargo.toml index 3204bbd79..322d0865f 100644 --- a/kvdb-rocksdb/Cargo.toml +++ b/kvdb-rocksdb/Cargo.toml @@ -4,7 +4,7 @@ version = "0.7.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "kvdb implementation backed by RocksDB" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [[bench]] diff --git a/kvdb-shared-tests/Cargo.toml b/kvdb-shared-tests/Cargo.toml index ff461caac..c5987c5c7 100644 --- a/kvdb-shared-tests/Cargo.toml +++ b/kvdb-shared-tests/Cargo.toml @@ -4,7 +4,7 @@ version = "0.2.0" authors = ["Parity Technologies "] edition = "2018" description = "Shared tests for kvdb functionality, to be executed against actual implementations" -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" [dependencies] kvdb = { path = "../kvdb", version = "0.5" } diff --git a/kvdb-web/Cargo.toml b/kvdb-web/Cargo.toml index 8d5fc7be4..331ef1fa6 100644 --- a/kvdb-web/Cargo.toml +++ b/kvdb-web/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "A key-value database for use in browsers" documentation = "https://docs.rs/kvdb-web/" -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" edition = "2018" [dependencies] diff --git a/kvdb/Cargo.toml b/kvdb/Cargo.toml index 669b19762..f6851ef33 100644 --- a/kvdb/Cargo.toml +++ b/kvdb/Cargo.toml @@ -4,7 +4,7 @@ version = "0.5.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Generic key-value trait" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [dependencies] diff --git a/parity-bytes/Cargo.toml b/parity-bytes/Cargo.toml index 384489203..651369f1c 100644 --- a/parity-bytes/Cargo.toml +++ b/parity-bytes/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.2" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "byte utilities for Parity" -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" edition = "2018" [dependencies] diff --git a/parity-crypto/Cargo.toml b/parity-crypto/Cargo.toml index f51bbd88f..763fc4b74 100644 --- a/parity-crypto/Cargo.toml +++ b/parity-crypto/Cargo.toml @@ -4,7 +4,7 @@ version = "0.6.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Crypto utils used by ethstore and network." -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" autobenches = false edition = "2018" diff --git a/parity-path/Cargo.toml b/parity-path/Cargo.toml index 8f272ad51..d23442c8f 100644 --- a/parity-path/Cargo.toml +++ b/parity-path/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.3" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Path utilities" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [dependencies] diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index 9f5e77039..af3916902 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -4,7 +4,7 @@ version = "0.6.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Collection of memory related utilities" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [dependencies] diff --git a/parity-util-mem/derive/Cargo.toml b/parity-util-mem/derive/Cargo.toml index b7648ebd2..d41ba12f5 100644 --- a/parity-util-mem/derive/Cargo.toml +++ b/parity-util-mem/derive/Cargo.toml @@ -2,7 +2,7 @@ name = "parity-util-mem-derive" version = "0.1.0" authors = ["Parity Technologies "] -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" description = "Crate for memory reporting" repository = "https://github.com/paritytech/pariry-common/parity-util-mem/derive" diff --git a/plain_hasher/Cargo.toml b/plain_hasher/Cargo.toml index 7e0812571..bb5a1668d 100644 --- a/plain_hasher/Cargo.toml +++ b/plain_hasher/Cargo.toml @@ -3,7 +3,7 @@ name = "plain_hasher" description = "Hasher for 32-byte keys." version = "0.2.3" authors = ["Parity Technologies "] -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" keywords = ["hash", "hasher"] homepage = "https://github.com/paritytech/parity-common" categories = ["no-std"] diff --git a/primitive-types/Cargo.toml b/primitive-types/Cargo.toml index 3169b5c2e..06e6e154d 100644 --- a/primitive-types/Cargo.toml +++ b/primitive-types/Cargo.toml @@ -2,7 +2,7 @@ name = "primitive-types" version = "0.7.0" authors = ["Parity Technologies "] -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" description = "Primitive types shared by Ethereum and Substrate" edition = "2018" diff --git a/primitive-types/impls/codec/Cargo.toml b/primitive-types/impls/codec/Cargo.toml index 4b39c10af..df837fd01 100644 --- a/primitive-types/impls/codec/Cargo.toml +++ b/primitive-types/impls/codec/Cargo.toml @@ -2,7 +2,7 @@ name = "impl-codec" version = "0.4.2" authors = ["Parity Technologies "] -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" description = "Parity Codec serialization support for uint and fixed hash." edition = "2018" diff --git a/primitive-types/impls/rlp/Cargo.toml b/primitive-types/impls/rlp/Cargo.toml index 85db3c328..fbc12c7fb 100644 --- a/primitive-types/impls/rlp/Cargo.toml +++ b/primitive-types/impls/rlp/Cargo.toml @@ -2,7 +2,7 @@ name = "impl-rlp" version = "0.2.1" authors = ["Parity Technologies "] -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" description = "RLP serialization support for uint and fixed hash." edition = "2018" diff --git a/primitive-types/impls/serde/Cargo.toml b/primitive-types/impls/serde/Cargo.toml index 641a59e6a..ab923bb63 100644 --- a/primitive-types/impls/serde/Cargo.toml +++ b/primitive-types/impls/serde/Cargo.toml @@ -3,7 +3,7 @@ name = "impl-serde" version = "0.3.0" authors = ["Parity Technologies "] edition = "2018" -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" description = "Serde serialization support for uint and fixed hash." diff --git a/rlp-derive/Cargo.toml b/rlp-derive/Cargo.toml index de3824a2f..5059d6d02 100644 --- a/rlp-derive/Cargo.toml +++ b/rlp-derive/Cargo.toml @@ -2,7 +2,7 @@ name = "rlp-derive" version = "0.1.0" authors = ["Parity Technologies "] -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" description = "Derive macro for #[derive(RlpEncodable, RlpDecodable)]" homepage = "http://parity.io" edition = "2018" diff --git a/rlp/Cargo.toml b/rlp/Cargo.toml index 947418a6b..cb8694c9e 100644 --- a/rlp/Cargo.toml +++ b/rlp/Cargo.toml @@ -3,7 +3,7 @@ name = "rlp" version = "0.4.5" description = "Recursive-length prefix encoding, decoding, and compression" repository = "https://github.com/paritytech/parity-common" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" authors = ["Parity Technologies "] edition = "2018" diff --git a/trace-time/Cargo.toml b/trace-time/Cargo.toml index 225cdec27..81877e186 100644 --- a/trace-time/Cargo.toml +++ b/trace-time/Cargo.toml @@ -4,7 +4,7 @@ description = "Easily trace time to execute a scope." version = "0.1.3" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" edition = "2018" [dependencies] diff --git a/transaction-pool/Cargo.toml b/transaction-pool/Cargo.toml index 2bf1dbb59..a13bc5767 100644 --- a/transaction-pool/Cargo.toml +++ b/transaction-pool/Cargo.toml @@ -2,7 +2,7 @@ description = "Generic transaction pool." name = "transaction-pool" version = "2.0.3" -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" edition = "2018" diff --git a/triehash/Cargo.toml b/triehash/Cargo.toml index 19496503a..358161a80 100644 --- a/triehash/Cargo.toml +++ b/triehash/Cargo.toml @@ -4,7 +4,7 @@ version = "0.8.3" authors = ["Parity Technologies "] description = "In-memory patricia trie operations" repository = "https://github.com/paritytech/parity-common" -license = "MIT/Apache2.0" +license = "MIT OR Apache-2.0" edition = "2018" [dependencies] diff --git a/uint/Cargo.toml b/uint/Cargo.toml index 3a61567a6..257b3fa7f 100644 --- a/uint/Cargo.toml +++ b/uint/Cargo.toml @@ -2,7 +2,7 @@ description = "Large fixed-size integer arithmetic" homepage = "http://parity.io" repository = "https://github.com/paritytech/parity-common" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" name = "uint" version = "0.8.2" authors = ["Parity Technologies "] From 8a29232801708e2679ee1f444136d76e6e340837 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Wed, 25 Mar 2020 18:46:49 +0100 Subject: [PATCH 39/56] Ban duplicates of parity-uil-mem from being linked into the same program (#363) * Prevent multiple versions of parity-uil-mem from being linked into the same program * fmt * parity-util-mem: add a warning about defining global allocs * parity-util-mem: document empty build script * parity-util-mem: extend the warning based on David comments --- parity-util-mem/CHANGELOG.md | 2 ++ parity-util-mem/Cargo.toml | 7 +++++++ parity-util-mem/README.md | 14 ++++++++++++++ parity-util-mem/build.rs | 1 + 4 files changed, 24 insertions(+) create mode 100644 parity-util-mem/build.rs diff --git a/parity-util-mem/CHANGELOG.md b/parity-util-mem/CHANGELOG.md index fdb3f5f7b..ec8ef91f9 100644 --- a/parity-util-mem/CHANGELOG.md +++ b/parity-util-mem/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Breaking +- Prevent multiple versions from being linked into the same program. [#363](https://github.com/paritytech/parity-common/pull/363) ## [0.6.0] - 2020-03-13 - Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index af3916902..700061c32 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -7,6 +7,13 @@ description = "Collection of memory related utilities" license = "MIT OR Apache-2.0" edition = "2018" +# Prevent multiple versions from being linked into the same program. +links = "parity-util-mem-ban-duplicates" +# `links` requires a build script to be present: +# https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key +# so we use an empty build script +build = "build.rs" + [dependencies] cfg-if = "0.1.10" dlmalloc = { version = "0.1.3", features = ["global"], optional = true } diff --git a/parity-util-mem/README.md b/parity-util-mem/README.md index 14d6e6c19..a6f15b90b 100644 --- a/parity-util-mem/README.md +++ b/parity-util-mem/README.md @@ -2,6 +2,20 @@ Collection of memory related utilities. +## WARNING + +When `parity-util-mem` is used as a dependency with any of the global allocator features enabled, +it must be the sole place where a global allocator is defined. +The only exception to this rule is when used in a `no_std` context or when the `estimate-heapsize` feature is used. + +Because of that, it must be present in the dependency tree with a single version. +Starting from version 0.7, having duplicate versions of `parity-util-mem` will lead +to a compile-time error. It still will be possible to have 0.6 and 0.7 versions in the same binary though. + +Unless heeded you risk UB; see discussion in [issue 364]. + +[issue 364]: https://github.com/paritytech/parity-common/issues/364 + ## Features - estimate-heapsize : Do not use allocator, but `size_of` or `size_of_val`. diff --git a/parity-util-mem/build.rs b/parity-util-mem/build.rs new file mode 100644 index 000000000..f328e4d9d --- /dev/null +++ b/parity-util-mem/build.rs @@ -0,0 +1 @@ +fn main() {} From 7093b7e63304b236ab5d654b137c656d8bf833f9 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Thu, 26 Mar 2020 15:18:49 +0100 Subject: [PATCH 40/56] kvdb: no overlay (#313) * kvdb-rocksdb: no overlay experiment * kvdb-rocksdb: remove unused dep * kvdb-rocksdb: panic on write failure * kvdb: remove write_buffered and flush * kvdb: update changelog * kvdb-rocksdb: update changelog * kvdb-web: update changelog * kvdb-memory: update changelog * kvdb-rocksdb: fix the bench * kvdb-rocksdb: fix the bench #2 * kvdb: cargo fmt * Apply suggestions from code review Co-Authored-By: David * kvdb-rocksdb: s/acquired_val/value * kvdb-rocksdb: update the changelog Co-authored-by: David --- kvdb-memorydb/CHANGELOG.md | 2 + kvdb-memorydb/src/lib.rs | 5 +- kvdb-rocksdb/CHANGELOG.md | 2 + kvdb-rocksdb/Cargo.toml | 1 - kvdb-rocksdb/benches/bench_read_perf.rs | 2 - kvdb-rocksdb/src/lib.rs | 186 +++--------------------- kvdb-shared-tests/src/lib.rs | 13 +- kvdb-web/CHANGELOG.md | 2 + kvdb-web/src/lib.rs | 10 +- kvdb-web/tests/indexed_db.rs | 2 +- kvdb/CHANGELOG.md | 2 + kvdb/src/lib.rs | 30 +--- 12 files changed, 48 insertions(+), 209 deletions(-) diff --git a/kvdb-memorydb/CHANGELOG.md b/kvdb-memorydb/CHANGELOG.md index a8c74772d..4db19fc7a 100644 --- a/kvdb-memorydb/CHANGELOG.md +++ b/kvdb-memorydb/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Breaking +- Updated to the new `kvdb` interface. [#313](https://github.com/paritytech/parity-common/pull/313) ## [0.5.0] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) diff --git a/kvdb-memorydb/src/lib.rs b/kvdb-memorydb/src/lib.rs index 51bac41f0..6977fbf4e 100644 --- a/kvdb-memorydb/src/lib.rs +++ b/kvdb-memorydb/src/lib.rs @@ -52,7 +52,7 @@ impl KeyValueDB for InMemory { } } - fn write_buffered(&self, transaction: DBTransaction) { + fn write(&self, transaction: DBTransaction) -> io::Result<()> { let mut columns = self.columns.write(); let ops = transaction.ops; for op in ops { @@ -69,9 +69,6 @@ impl KeyValueDB for InMemory { } } } - } - - fn flush(&self) -> io::Result<()> { Ok(()) } diff --git a/kvdb-rocksdb/CHANGELOG.md b/kvdb-rocksdb/CHANGELOG.md index e7561c059..43cf44408 100644 --- a/kvdb-rocksdb/CHANGELOG.md +++ b/kvdb-rocksdb/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Breaking +- Updated to the new `kvdb` interface. [#313](https://github.com/paritytech/parity-common/pull/313) ## [0.7.0] - 2020-03-16 - Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) diff --git a/kvdb-rocksdb/Cargo.toml b/kvdb-rocksdb/Cargo.toml index 322d0865f..315b4d864 100644 --- a/kvdb-rocksdb/Cargo.toml +++ b/kvdb-rocksdb/Cargo.toml @@ -14,7 +14,6 @@ harness = false [dependencies] smallvec = "1.0.0" fs-swap = "0.2.4" -interleaved-ordered = "0.1.1" kvdb = { path = "../kvdb", version = "0.5" } log = "0.4.8" num_cpus = "1.10.1" diff --git a/kvdb-rocksdb/benches/bench_read_perf.rs b/kvdb-rocksdb/benches/bench_read_perf.rs index 8c17d8981..3a14ac752 100644 --- a/kvdb-rocksdb/benches/bench_read_perf.rs +++ b/kvdb-rocksdb/benches/bench_read_perf.rs @@ -76,8 +76,6 @@ fn populate(db: &Database) -> io::Result> { batch.put(0, &key.as_bytes(), &n_random_bytes(140)); } db.write(batch)?; - // Clear the overlay - db.flush()?; Ok(needles) } diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index ac8958919..8755f207f 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -12,15 +12,14 @@ mod stats; use std::{cmp, collections::HashMap, convert::identity, error, fs, io, mem, path::Path, result}; use parity_util_mem::MallocSizeOf; -use parking_lot::{Mutex, MutexGuard, RwLock}; +use parking_lot::RwLock; use rocksdb::{ BlockBasedOptions, ColumnFamily, ColumnFamilyDescriptor, Error, Options, ReadOptions, WriteBatch, WriteOptions, DB, }; use crate::iter::KeyValuePair; use fs_swap::{swap, swap_nonatomic}; -use interleaved_ordered::interleave_ordered; -use kvdb::{DBKey, DBOp, DBTransaction, DBValue, KeyValueDB}; +use kvdb::{DBOp, DBTransaction, DBValue, KeyValueDB}; use log::{debug, warn}; #[cfg(target_os = "linux")] @@ -51,12 +50,6 @@ pub const DB_DEFAULT_COLUMN_MEMORY_BUDGET_MB: MiB = 128; /// The default memory budget in MiB. pub const DB_DEFAULT_MEMORY_BUDGET_MB: MiB = 512; -#[derive(MallocSizeOf)] -enum KeyState { - Insert(DBValue), - Delete, -} - /// Compaction profile for the database settings /// Note, that changing these parameters may trigger /// the compaction process of RocksDB on startup. @@ -281,15 +274,8 @@ pub struct Database { read_opts: ReadOptions, #[ignore_malloc_size_of = "insignificant"] block_opts: BlockBasedOptions, - // Dirty values added with `write_buffered`. Cleaned on `flush`. - overlay: RwLock>>, #[ignore_malloc_size_of = "insignificant"] stats: stats::RunningDbStats, - // Values currently being flushed. Cleared when `flush` completes. - flushing: RwLock>>, - // Prevents concurrent flushes. - // Value indicates if a flush is in progress. - flushing_lock: Mutex, } #[inline] @@ -418,9 +404,6 @@ impl Database { Ok(Database { db: RwLock::new(Some(DBAndColumns { db, column_names })), config: config.clone(), - overlay: RwLock::new((0..config.columns).map(|_| HashMap::new()).collect()), - flushing: RwLock::new((0..config.columns).map(|_| HashMap::new()).collect()), - flushing_lock: Mutex::new(false), path: path.to_owned(), opts, read_opts, @@ -435,75 +418,6 @@ impl Database { DBTransaction::new() } - /// Commit transaction to database. - pub fn write_buffered(&self, tr: DBTransaction) { - let mut overlay = self.overlay.write(); - let ops = tr.ops; - for op in ops { - match op { - DBOp::Insert { col, key, value } => overlay[col as usize].insert(key, KeyState::Insert(value)), - DBOp::Delete { col, key } => overlay[col as usize].insert(key, KeyState::Delete), - }; - } - } - - /// Commit buffered changes to database. Must be called under `flush_lock` - fn write_flushing_with_lock(&self, _lock: &mut MutexGuard<'_, bool>) -> io::Result<()> { - match *self.db.read() { - Some(ref cfs) => { - let mut batch = WriteBatch::default(); - let mut ops: usize = 0; - let mut bytes: usize = 0; - mem::swap(&mut *self.overlay.write(), &mut *self.flushing.write()); - { - for (c, column) in self.flushing.read().iter().enumerate() { - ops += column.len(); - for (key, state) in column.iter() { - let cf = cfs.cf(c); - match *state { - KeyState::Delete => { - bytes += key.len(); - batch.delete_cf(cf, key).map_err(other_io_err)? - } - KeyState::Insert(ref value) => { - bytes += key.len() + value.len(); - batch.put_cf(cf, key, value).map_err(other_io_err)? - } - }; - } - } - } - - check_for_corruption(&self.path, cfs.db.write_opt(batch, &self.write_opts))?; - self.stats.tally_transactions(1); - self.stats.tally_writes(ops as u64); - self.stats.tally_bytes_written(bytes as u64); - - for column in self.flushing.write().iter_mut() { - column.clear(); - column.shrink_to_fit(); - } - Ok(()) - } - None => Err(other_io_err("Database is closed")), - } - } - - /// Commit buffered changes to database. - pub fn flush(&self) -> io::Result<()> { - let mut lock = self.flushing_lock.lock(); - // If RocksDB batch allocation fails the thread gets terminated and the lock is released. - // The value inside the lock is used to detect that. - if *lock { - // This can only happen if another flushing thread is terminated unexpectedly. - return Err(other_io_err("Database write failure. Running low on memory perhaps?")); - } - *lock = true; - let result = self.write_flushing_with_lock(&mut lock); - *lock = false; - result - } - /// Commit transaction to database. pub fn write(&self, tr: DBTransaction) -> io::Result<()> { match *self.db.read() { @@ -517,9 +431,6 @@ impl Database { let mut stats_total_bytes = 0; for op in ops { - // remove any buffered operation for this key - self.overlay.write()[op.col() as usize].remove(op.key()); - let cf = cfs.cf(op.col() as usize); match op { @@ -546,84 +457,55 @@ impl Database { pub fn get(&self, col: u32, key: &[u8]) -> io::Result> { match *self.db.read() { Some(ref cfs) => { - self.stats.tally_reads(1); - let guard = self.overlay.read(); - let overlay = - guard.get(col as usize).ok_or_else(|| other_io_err("kvdb column index is out of bounds"))?; - match overlay.get(key) { - Some(&KeyState::Insert(ref value)) => Ok(Some(value.clone())), - Some(&KeyState::Delete) => Ok(None), - None => { - let flushing = &self.flushing.read()[col as usize]; - match flushing.get(key) { - Some(&KeyState::Insert(ref value)) => Ok(Some(value.clone())), - Some(&KeyState::Delete) => Ok(None), - None => { - let acquired_val = cfs - .db - .get_pinned_cf_opt(cfs.cf(col as usize), key, &self.read_opts) - .map(|r| r.map(|v| v.to_vec())) - .map_err(other_io_err); - - match acquired_val { - Ok(Some(ref v)) => self.stats.tally_bytes_read((key.len() + v.len()) as u64), - Ok(None) => self.stats.tally_bytes_read(key.len() as u64), - _ => {} - }; - - acquired_val - } - } - } + if cfs.column_names.get(col as usize).is_none() { + return Err(other_io_err("column index is out of bounds")); } + self.stats.tally_reads(1); + let value = cfs + .db + .get_pinned_cf_opt(cfs.cf(col as usize), key, &self.read_opts) + .map(|r| r.map(|v| v.to_vec())) + .map_err(other_io_err); + + match value { + Ok(Some(ref v)) => self.stats.tally_bytes_read((key.len() + v.len()) as u64), + Ok(None) => self.stats.tally_bytes_read(key.len() as u64), + _ => {} + }; + + value } None => Ok(None), } } - /// Get value by partial key. Prefix size should match configured prefix size. Only searches flushed values. - // TODO: support prefix seek for unflushed data + /// Get value by partial key. Prefix size should match configured prefix size. pub fn get_by_prefix(&self, col: u32, prefix: &[u8]) -> Option> { self.iter_from_prefix(col, prefix).next().map(|(_, v)| v) } - /// Get database iterator for flushed data. + /// Iterator over the data in the given database column index. /// Will hold a lock until the iterator is dropped /// preventing the database from being closed. pub fn iter<'a>(&'a self, col: u32) -> impl Iterator + 'a { let read_lock = self.db.read(); let optional = if read_lock.is_some() { - let overlay_data = { - let overlay = &self.overlay.read()[col as usize]; - let mut overlay_data = overlay - .iter() - .filter_map(|(k, v)| match *v { - KeyState::Insert(ref value) => { - Some((k.clone().into_vec().into_boxed_slice(), value.clone().into_boxed_slice())) - } - KeyState::Delete => None, - }) - .collect::>(); - overlay_data.sort(); - overlay_data - }; - let guarded = iter::ReadGuardedIterator::new(read_lock, col, &self.read_opts); - Some(interleave_ordered(overlay_data, guarded)) + Some(guarded) } else { None }; optional.into_iter().flat_map(identity) } - /// Get database iterator from prefix for flushed data. + /// Iterator over data in the `col` database column index matching the given prefix. /// Will hold a lock until the iterator is dropped /// preventing the database from being closed. fn iter_from_prefix<'a>(&'a self, col: u32, prefix: &'a [u8]) -> impl Iterator + 'a { let read_lock = self.db.read(); let optional = if read_lock.is_some() { let guarded = iter::ReadGuardedIterator::new_from_prefix(read_lock, col, prefix, &self.read_opts); - Some(interleave_ordered(Vec::new(), guarded)) + Some(guarded) } else { None }; @@ -636,8 +518,6 @@ impl Database { /// Close the database fn close(&self) { *self.db.write() = None; - self.overlay.write().clear(); - self.flushing.write().clear(); } /// Restore the database from a copy at given path. @@ -671,8 +551,6 @@ impl Database { // reopen the database and steal handles into self let db = Self::open(&self.config, &self.path)?; *self.db.write() = mem::replace(&mut *db.db.write(), None); - *self.overlay.write() = mem::replace(&mut *db.overlay.write(), Vec::new()); - *self.flushing.write() = mem::replace(&mut *db.flushing.write(), Vec::new()); Ok(()) } @@ -687,7 +565,6 @@ impl Database { } /// The number of keys in a column (estimated). - /// Does not take into account the unflushed data. pub fn num_keys(&self, col: u32) -> io::Result { const ESTIMATE_NUM_KEYS: &str = "rocksdb.estimate-num-keys"; match *self.db.read() { @@ -751,18 +628,10 @@ impl KeyValueDB for Database { Database::get_by_prefix(self, col, prefix) } - fn write_buffered(&self, transaction: DBTransaction) { - Database::write_buffered(self, transaction) - } - fn write(&self, transaction: DBTransaction) -> io::Result<()> { Database::write(self, transaction) } - fn flush(&self) -> io::Result<()> { - Database::flush(self) - } - fn iter<'a>(&'a self, col: u32) -> Box + 'a> { let unboxed = Database::iter(self, col); Box::new(unboxed.into_iter()) @@ -805,13 +674,6 @@ impl KeyValueDB for Database { } } -impl Drop for Database { - fn drop(&mut self) { - // write all buffered changes if we can. - let _ = self.flush(); - } -} - #[cfg(test)] mod tests { use super::*; @@ -888,8 +750,6 @@ mod tests { } db.write(batch).unwrap(); - db.flush().unwrap(); - { let db = db.db.read(); db.as_ref().map(|db| { diff --git a/kvdb-shared-tests/src/lib.rs b/kvdb-shared-tests/src/lib.rs index ca82dc8cd..35de99239 100644 --- a/kvdb-shared-tests/src/lib.rs +++ b/kvdb-shared-tests/src/lib.rs @@ -17,7 +17,7 @@ pub fn test_put_and_get(db: &dyn KeyValueDB) -> io::Result<()> { let mut transaction = db.transaction(); transaction.put(0, key1, b"horse"); - db.write_buffered(transaction); + db.write(transaction)?; assert_eq!(&*db.get(0, key1)?.unwrap(), b"horse"); Ok(()) } @@ -28,12 +28,12 @@ pub fn test_delete_and_get(db: &dyn KeyValueDB) -> io::Result<()> { let mut transaction = db.transaction(); transaction.put(0, key1, b"horse"); - db.write_buffered(transaction); + db.write(transaction)?; assert_eq!(&*db.get(0, key1)?.unwrap(), b"horse"); let mut transaction = db.transaction(); transaction.delete(0, key1); - db.write_buffered(transaction); + db.write(transaction)?; assert!(db.get(0, key1)?.is_none()); Ok(()) } @@ -49,7 +49,7 @@ pub fn test_get_fails_with_non_existing_column(db: &dyn KeyValueDB) -> io::Resul pub fn test_write_clears_buffered_ops(db: &dyn KeyValueDB) -> io::Result<()> { let mut batch = db.transaction(); batch.put(0, b"foo", b"bar"); - db.write_buffered(batch); + db.write(batch)?; assert_eq!(db.get(0, b"foo")?.unwrap(), b"bar"); @@ -69,7 +69,7 @@ pub fn test_iter(db: &dyn KeyValueDB) -> io::Result<()> { let mut transaction = db.transaction(); transaction.put(0, key1, key1); transaction.put(0, key2, key2); - db.write_buffered(transaction); + db.write(transaction)?; let contents: Vec<_> = db.iter(0).into_iter().collect(); assert_eq!(contents.len(), 2); @@ -224,11 +224,10 @@ pub fn test_complex(db: &dyn KeyValueDB) -> io::Result<()> { let mut transaction = db.transaction(); transaction.put(0, key1, b"horse"); transaction.delete(0, key3); - db.write_buffered(transaction); + db.write(transaction)?; assert!(db.get(0, key3)?.is_none()); assert_eq!(&*db.get(0, key1)?.unwrap(), b"horse"); - db.flush()?; assert!(db.get(0, key3)?.is_none()); assert_eq!(&*db.get(0, key1)?.unwrap(), b"horse"); Ok(()) diff --git a/kvdb-web/CHANGELOG.md b/kvdb-web/CHANGELOG.md index f8e952bf3..97fa61f4f 100644 --- a/kvdb-web/CHANGELOG.md +++ b/kvdb-web/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Breaking +- Updated to the new `kvdb` interface. [#313](https://github.com/paritytech/parity-common/pull/313) ## [0.5.0] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) diff --git a/kvdb-web/src/lib.rs b/kvdb-web/src/lib.rs index 5d9878ec2..f0179c085 100644 --- a/kvdb-web/src/lib.rs +++ b/kvdb-web/src/lib.rs @@ -71,7 +71,7 @@ impl Database { txn.put_vec(column, key.as_ref(), value); } // write each column into memory - in_memory.write_buffered(txn); + in_memory.write(txn).expect("writing in memory always succeeds; qed"); } Ok(Database { name: name_clone, version, columns, in_memory, indexed_db: inner }) } @@ -102,13 +102,9 @@ impl KeyValueDB for Database { self.in_memory.get_by_prefix(col, prefix) } - fn write_buffered(&self, transaction: DBTransaction) { + fn write(&self, transaction: DBTransaction) -> io::Result<()> { let _ = indexed_db::idb_commit_transaction(&*self.indexed_db, &transaction, self.columns); - self.in_memory.write_buffered(transaction); - } - - fn flush(&self) -> io::Result<()> { - Ok(()) + self.in_memory.write(transaction) } // NOTE: clones the whole db diff --git a/kvdb-web/tests/indexed_db.rs b/kvdb-web/tests/indexed_db.rs index 81a765a05..43c7ce83c 100644 --- a/kvdb-web/tests/indexed_db.rs +++ b/kvdb-web/tests/indexed_db.rs @@ -66,7 +66,7 @@ async fn reopen_the_database_with_more_columns() { // Write a value into the database let mut batch = db.transaction(); batch.put(0, b"hello", b"world"); - db.write_buffered(batch); + db.write(batch).unwrap(); assert_eq!(db.get(0, b"hello").unwrap().unwrap(), b"world"); diff --git a/kvdb/CHANGELOG.md b/kvdb/CHANGELOG.md index 18f484117..6cfa99a6e 100644 --- a/kvdb/CHANGELOG.md +++ b/kvdb/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Breaking +- Removed `write_buffered` and `flush` methods. [#313](https://github.com/paritytech/parity-common/pull/313) ## [0.5.0] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) diff --git a/kvdb/src/lib.rs b/kvdb/src/lib.rs index 723714de5..0fd28d9b8 100644 --- a/kvdb/src/lib.rs +++ b/kvdb/src/lib.rs @@ -84,19 +84,10 @@ impl DBTransaction { /// Generic key-value database. /// -/// This makes a distinction between "buffered" and "flushed" values. Values which have been -/// written can always be read, but may be present in an in-memory buffer. Values which have -/// been flushed have been moved to backing storage, like a RocksDB instance. There are certain -/// operations which are only guaranteed to operate on flushed data and not buffered, -/// although implementations may differ in this regard. -/// -/// The contents of an interior buffer may be explicitly flushed using the `flush` method. -/// -/// The `KeyValueDB` also deals in "column families", which can be thought of as distinct +/// The `KeyValueDB` deals with "column families", which can be thought of as distinct /// stores within a database. Keys written in one column family will not be accessible from /// any other. The number of column families must be specified at initialization, with a -/// differing interface for each database. The `None` argument in place of a column index -/// is always supported. +/// differing interface for each database. /// /// The API laid out here, along with the `Sync` bound implies interior synchronization for /// implementation. @@ -109,25 +100,16 @@ pub trait KeyValueDB: Sync + Send + parity_util_mem::MallocSizeOf { /// Get a value by key. fn get(&self, col: u32, key: &[u8]) -> io::Result>; - /// Get a value by partial key. Only works for flushed data. + /// Get the first value matching the given prefix. fn get_by_prefix(&self, col: u32, prefix: &[u8]) -> Option>; - /// Write a transaction of changes to the buffer. - fn write_buffered(&self, transaction: DBTransaction); - /// Write a transaction of changes to the backing store. - fn write(&self, transaction: DBTransaction) -> io::Result<()> { - self.write_buffered(transaction); - self.flush() - } - - /// Flush all buffered data. - fn flush(&self) -> io::Result<()>; + fn write(&self, transaction: DBTransaction) -> io::Result<()>; - /// Iterate over flushed data for a given column. + /// Iterate over the data for a given column. fn iter<'a>(&'a self, col: u32) -> Box, Box<[u8]>)> + 'a>; - /// Iterate over flushed data for a given column, starting from a given prefix. + /// Iterate over the data for a given column, starting from a given prefix. fn iter_from_prefix<'a>( &'a self, col: u32, From dd89c9a00b82b9e5c4e18964fd452c0dca5eed3c Mon Sep 17 00:00:00 2001 From: cheme Date: Fri, 27 Mar 2020 20:11:56 +0100 Subject: [PATCH 41/56] Delete by prefix operator in kvdb (#360) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Switch from `parity-rocksdb` to upstream `rust-rocksdb` * Update to latest rocksdb * Delete prefix as range exept when start is full of 255 (corner case). * forcing ignore lifetime (not more unsafe than before, columnfamily is probably not an issue, dbiterator is one as it will fail on close db). * remove temporarilly path deps for easier patch usage. * being a bit more exhaustive * Tests for delete prefix, fix rocksdb full column delete. * revert util-mem * update versionning. * better end prefix from review * revert test error check * Update kvdb-memorydb/src/lib.rs Co-Authored-By: Andronik Ordian * Update kvdb-shared-tests/src/lib.rs Co-Authored-By: Andronik Ordian * Update kvdb/src/lib.rs Co-Authored-By: Andronik Ordian * Update kvdb/src/lib.rs Co-Authored-By: Andronik Ordian * applying suggestions, and remove delete by prefix method. * io stats num column * end_prefix test * format * Redundant delete. * Update kvdb/src/lib.rs Co-Authored-By: David * Update kvdb/src/lib.rs Co-Authored-By: David * Documentation fix and additional test case in end_prefix_test * Doc. * doc Co-authored-by: Bastian Köcher Co-authored-by: Benjamin Kampmann Co-authored-by: Andronik Ordian Co-authored-by: David --- kvdb-memorydb/Cargo.toml | 2 +- kvdb-memorydb/src/lib.rs | 21 +++++++++++++ kvdb-rocksdb/Cargo.toml | 2 +- kvdb-rocksdb/src/lib.rs | 19 +++++++++++- kvdb-shared-tests/Cargo.toml | 2 +- kvdb-shared-tests/src/lib.rs | 60 ++++++++++++++++++++++++++++++++++++ kvdb-web/Cargo.toml | 3 +- kvdb-web/src/indexed_db.rs | 15 ++++++++- kvdb-web/tests/indexed_db.rs | 6 ++++ kvdb/src/lib.rs | 44 ++++++++++++++++++++++++++ 10 files changed, 168 insertions(+), 6 deletions(-) diff --git a/kvdb-memorydb/Cargo.toml b/kvdb-memorydb/Cargo.toml index 0ea7119a8..290727c75 100644 --- a/kvdb-memorydb/Cargo.toml +++ b/kvdb-memorydb/Cargo.toml @@ -13,4 +13,4 @@ parking_lot = "0.10.0" kvdb = { version = "0.5", path = "../kvdb" } [dev-dependencies] -kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.2" } +kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.3" } diff --git a/kvdb-memorydb/src/lib.rs b/kvdb-memorydb/src/lib.rs index 6977fbf4e..c37ed821f 100644 --- a/kvdb-memorydb/src/lib.rs +++ b/kvdb-memorydb/src/lib.rs @@ -67,6 +67,21 @@ impl KeyValueDB for InMemory { col.remove(&*key); } } + DBOp::DeletePrefix { col, prefix } => { + if let Some(col) = columns.get_mut(&col) { + use std::ops::Bound; + if prefix.is_empty() { + col.clear(); + } else { + let start_range = Bound::Included(prefix.to_vec()); + let end_range = Bound::Excluded(kvdb::end_prefix(&prefix[..])); + let keys: Vec<_> = col.range((start_range, end_range)).map(|(k, _)| k.clone()).collect(); + for key in keys.into_iter() { + col.remove(&key[..]); + } + } + } + } } } Ok(()) @@ -127,6 +142,12 @@ mod tests { st::test_delete_and_get(&db) } + #[test] + fn delete_prefix() -> io::Result<()> { + let db = create(st::DELETE_PREFIX_NUM_COLUMNS); + st::test_delete_prefix(&db) + } + #[test] fn iter() -> io::Result<()> { let db = create(1); diff --git a/kvdb-rocksdb/Cargo.toml b/kvdb-rocksdb/Cargo.toml index 315b4d864..77812b6fe 100644 --- a/kvdb-rocksdb/Cargo.toml +++ b/kvdb-rocksdb/Cargo.toml @@ -27,7 +27,7 @@ parity-util-mem = { path = "../parity-util-mem", version = "0.6", default-featur alloc_counter = "0.0.4" criterion = "0.3" ethereum-types = { path = "../ethereum-types" } -kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.2" } +kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.3" } rand = "0.7.2" tempdir = "0.3.7" keccak-hash = { path = "../keccak-hash" } diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index 8755f207f..54a81140c 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -443,6 +443,17 @@ impl Database { stats_total_bytes += key.len(); batch.delete_cf(cf, &key).map_err(other_io_err)? } + DBOp::DeletePrefix { col: _, prefix } => { + if prefix.len() > 0 { + let end_range = kvdb::end_prefix(&prefix[..]); + batch.delete_range_cf(cf, &prefix[..], &end_range[..]).map_err(other_io_err)?; + } else { + // Deletes all values in the column. + let end_range = &[u8::max_value()]; + batch.delete_range_cf(cf, &prefix[..], &end_range[..]).map_err(other_io_err)?; + batch.delete_cf(cf, &end_range[..]).map_err(other_io_err)?; + } + } }; } self.stats.tally_bytes_written(stats_total_bytes as u64); @@ -705,6 +716,12 @@ mod tests { st::test_delete_and_get(&db) } + #[test] + fn delete_prefix() -> io::Result<()> { + let db = create(st::DELETE_PREFIX_NUM_COLUMNS)?; + st::test_delete_prefix(&db) + } + #[test] fn iter() -> io::Result<()> { let db = create(1)?; @@ -725,7 +742,7 @@ mod tests { #[test] fn stats() -> io::Result<()> { - let db = create(3)?; + let db = create(st::IOSTATS_NUM_COLUMNS)?; st::test_io_stats(&db) } diff --git a/kvdb-shared-tests/Cargo.toml b/kvdb-shared-tests/Cargo.toml index c5987c5c7..e6f0876c7 100644 --- a/kvdb-shared-tests/Cargo.toml +++ b/kvdb-shared-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kvdb-shared-tests" -version = "0.2.0" +version = "0.3.0" authors = ["Parity Technologies "] edition = "2018" description = "Shared tests for kvdb functionality, to be executed against actual implementations" diff --git a/kvdb-shared-tests/src/lib.rs b/kvdb-shared-tests/src/lib.rs index 35de99239..2ffcc07ef 100644 --- a/kvdb-shared-tests/src/lib.rs +++ b/kvdb-shared-tests/src/lib.rs @@ -126,6 +126,9 @@ pub fn test_iter_from_prefix(db: &dyn KeyValueDB) -> io::Result<()> { Ok(()) } +/// The number of columns required to run `test_io_stats`. +pub const IOSTATS_NUM_COLUMNS: u32 = 3; + /// A test for `KeyValueDB::io_stats`. /// Assumes that the `db` has at least 3 columns. pub fn test_io_stats(db: &dyn KeyValueDB) -> io::Result<()> { @@ -171,6 +174,63 @@ pub fn test_io_stats(db: &dyn KeyValueDB) -> io::Result<()> { Ok(()) } +/// The number of columns required to run `test_delete_prefix`. +pub const DELETE_PREFIX_NUM_COLUMNS: u32 = 5; + +/// A test for `KeyValueDB::delete_prefix`. +pub fn test_delete_prefix(db: &dyn KeyValueDB) -> io::Result<()> { + let keys = [ + &[][..], + &[0u8][..], + &[0, 1][..], + &[1][..], + &[1, 0][..], + &[1, 255][..], + &[1, 255, 255][..], + &[2][..], + &[2, 0][..], + &[2, 255][..], + ]; + let init_db = |ix: u32| -> io::Result<()> { + let mut batch = db.transaction(); + for (i, key) in keys.iter().enumerate() { + batch.put(ix, key, &[i as u8]); + } + db.write(batch)?; + Ok(()) + }; + let check_db = |ix: u32, content: [bool; 10]| -> io::Result<()> { + let mut state = [true; 10]; + for (c, key) in keys.iter().enumerate() { + state[c] = db.get(ix, key)?.is_some(); + } + assert_eq!(state, content, "at {}", ix); + Ok(()) + }; + let tests: [_; DELETE_PREFIX_NUM_COLUMNS as usize] = [ + // standard + (&[1u8][..], [true, true, true, false, false, false, false, true, true, true]), + // edge + (&[1u8, 255, 255][..], [true, true, true, true, true, true, false, true, true, true]), + // none 1 + (&[1, 2][..], [true, true, true, true, true, true, true, true, true, true]), + // none 2 + (&[8][..], [true, true, true, true, true, true, true, true, true, true]), + // all + (&[][..], [false, false, false, false, false, false, false, false, false, false]), + ]; + for (ix, test) in tests.iter().enumerate() { + let ix = ix as u32; + init_db(ix)?; + let mut batch = db.transaction(); + batch.delete_prefix(ix, test.0); + db.write(batch)?; + check_db(ix, test.1)?; + } + + Ok(()) +} + /// A complex test. pub fn test_complex(db: &dyn KeyValueDB) -> io::Result<()> { let key1 = b"02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc"; diff --git a/kvdb-web/Cargo.toml b/kvdb-web/Cargo.toml index 331ef1fa6..2a9a681d6 100644 --- a/kvdb-web/Cargo.toml +++ b/kvdb-web/Cargo.toml @@ -34,11 +34,12 @@ features = [ 'EventTarget', 'IdbCursor', 'IdbCursorWithValue', + 'IdbKeyRange', 'DomStringList', ] [dev-dependencies] console_log = "0.1.2" -kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.2" } +kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.3" } wasm-bindgen-test = "0.3.4" wasm-bindgen-futures = "0.4.4" diff --git a/kvdb-web/src/indexed_db.rs b/kvdb-web/src/indexed_db.rs index 4593e3007..15a7713e6 100644 --- a/kvdb-web/src/indexed_db.rs +++ b/kvdb-web/src/indexed_db.rs @@ -10,7 +10,7 @@ use js_sys::{Array, ArrayBuffer, Uint8Array}; use wasm_bindgen::{closure::Closure, JsCast, JsValue}; -use web_sys::{Event, IdbCursorWithValue, IdbDatabase, IdbOpenDbRequest, IdbRequest, IdbTransactionMode}; +use web_sys::{Event, IdbCursorWithValue, IdbDatabase, IdbKeyRange, IdbOpenDbRequest, IdbRequest, IdbTransactionMode}; use futures::channel; use futures::prelude::*; @@ -157,6 +157,19 @@ pub fn idb_commit_transaction(idb: &IdbDatabase, txn: &DBTransaction, columns: u warn!("error deleting key from col_{}: {:?}", column, err); } } + DBOp::DeletePrefix { col, prefix } => { + let column = *col as usize; + // Convert rust bytes to js arrays + let prefix_js_start = Uint8Array::from(prefix.as_ref()); + let prefix_js_end = Uint8Array::from(prefix.as_ref()); + + let range = IdbKeyRange::bound(prefix_js_start.as_ref(), prefix_js_end.as_ref()) + .expect("Starting and ending at same value is valid bound; qed"); + let res = object_stores[column].delete(range.as_ref()); + if let Err(err) = res { + warn!("error deleting prefix from col_{}: {:?}", column, err); + } + } } } diff --git a/kvdb-web/tests/indexed_db.rs b/kvdb-web/tests/indexed_db.rs index 43c7ce83c..e32d5ea18 100644 --- a/kvdb-web/tests/indexed_db.rs +++ b/kvdb-web/tests/indexed_db.rs @@ -39,6 +39,12 @@ async fn delete_and_get() { st::test_delete_and_get(&db).unwrap() } +#[wasm_bindgen_test] +async fn delete_prefix() { + let db = open_db(st::DELETE_PREFIX_NUM_COLUMNS, "delete_prefix").await; + st::test_delete_prefix(&db).unwrap() +} + #[wasm_bindgen_test] async fn iter() { let db = open_db(1, "iter").await; diff --git a/kvdb/src/lib.rs b/kvdb/src/lib.rs index 0fd28d9b8..695519f43 100644 --- a/kvdb/src/lib.rs +++ b/kvdb/src/lib.rs @@ -35,6 +35,7 @@ pub struct DBTransaction { pub enum DBOp { Insert { col: u32, key: DBKey, value: DBValue }, Delete { col: u32, key: DBKey }, + DeletePrefix { col: u32, prefix: DBKey }, } impl DBOp { @@ -43,6 +44,7 @@ impl DBOp { match *self { DBOp::Insert { ref key, .. } => key, DBOp::Delete { ref key, .. } => key, + DBOp::DeletePrefix { ref prefix, .. } => prefix, } } @@ -51,6 +53,7 @@ impl DBOp { match *self { DBOp::Insert { col, .. } => col, DBOp::Delete { col, .. } => col, + DBOp::DeletePrefix { col, .. } => col, } } } @@ -80,6 +83,13 @@ impl DBTransaction { pub fn delete(&mut self, col: u32, key: &[u8]) { self.ops.push(DBOp::Delete { col, key: DBKey::from_slice(key) }); } + + /// Delete all values with the given key prefix. + /// Using an empty prefix here will remove all keys + /// (all keys starts with the empty prefix). + pub fn delete_prefix(&mut self, col: u32, prefix: &[u8]) { + self.ops.push(DBOp::DeletePrefix { col, prefix: DBKey::from_slice(prefix) }); + } } /// Generic key-value database. @@ -129,3 +139,37 @@ pub trait KeyValueDB: Sync + Send + parity_util_mem::MallocSizeOf { IoStats::empty() } } + +/// For a given start prefix (inclusive), returns the correct end prefix (non-inclusive). +/// This assumes the key bytes are ordered in lexicographical order. +pub fn end_prefix(prefix: &[u8]) -> Vec { + let mut end_range = prefix.to_vec(); + while let Some(0xff) = end_range.last() { + end_range.pop(); + } + if let Some(byte) = end_range.last_mut() { + *byte += 1; + } + end_range +} + +#[cfg(test)] +mod test { + use super::end_prefix; + + #[test] + fn end_prefix_test() { + assert_eq!(end_prefix(&[5, 6, 7]), vec![5, 6, 8]); + assert_eq!(end_prefix(&[5, 6, 255]), vec![5, 7]); + // This is not equal as the result is before start. + assert_ne!(end_prefix(&[5, 255, 255]), vec![5, 255]); + // This is equal ([5, 255] will not be deleted because + // it is before start). + assert_eq!(end_prefix(&[5, 255, 255]), vec![6]); + assert_eq!(end_prefix(&[255, 255, 255]), vec![]); + + assert_eq!(end_prefix(&[0x00, 0xff]), vec![0x01]); + assert_eq!(end_prefix(&[0xff]), vec![]); + assert_eq!(end_prefix(&[]), vec![]); + } +} From b87aee1d54bb372471b92e0d25970bcdc9d6e002 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 10 Apr 2020 12:43:21 +0200 Subject: [PATCH 42/56] Allow pubkey recovery for all-zero messages (#369) * Allow pubkey recovery for all-zero messages After https://github.com/openethereum/openethereum/pull/11406 it is no longer possible to to public key recovery from messages that are all-zero. This create issues when using the `ecrecover` builtin because externally produced signatures may well provide a message (i.e. a preimage) that is all-zeroes. This works around the problem at the cost of cloning the incoming message and create a `ZeroesAllowedMessage` wrapper around it. The `ZeroesAllowedMessage` implements the `ThirtyTwoByteHash` trait from `rust-secp256k1` which circumvents the zero-check. In a follow-up PR we'll likely change the interface of `recover()` to take a `ZeroesAllowedMessage` directly, thus removing the unneeded clone. * Inner doesn't need to be pub * Update parity-crypto/src/publickey/ecdsa_signature.rs Co-Authored-By: Andronik Ordian * Docs and review grumbles * Add `recover_allowing_all_zero_message()` Revert `recover()` to previous behaviour: no zero-messages allowed Docs and cleanup * Obey the fmt Co-authored-by: Andronik Ordian --- .../src/publickey/ecdsa_signature.rs | 62 +++++++++++++++++-- parity-crypto/src/publickey/mod.rs | 20 +++++- 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/parity-crypto/src/publickey/ecdsa_signature.rs b/parity-crypto/src/publickey/ecdsa_signature.rs index 6853b1586..7968967a7 100644 --- a/parity-crypto/src/publickey/ecdsa_signature.rs +++ b/parity-crypto/src/publickey/ecdsa_signature.rs @@ -8,7 +8,7 @@ //! Signature based on ECDSA, algorithm's description: https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm -use super::{public_to_address, Address, Error, Message, Public, Secret, SECP256K1}; +use super::{public_to_address, Address, Error, Message, Public, Secret, ZeroesAllowedMessage, SECP256K1}; use ethereum_types::{H256, H520}; use rustc_hex::{FromHex, ToHex}; use secp256k1::key::{PublicKey, SecretKey}; @@ -246,22 +246,56 @@ pub fn verify_address(address: &Address, signature: &Signature, message: &Messag /// Recovers the public key from the signature for the message pub fn recover(signature: &Signature, message: &Message) -> Result { - let context = &SECP256K1; let rsig = RecoverableSignature::from_compact(&signature[0..64], RecoveryId::from_i32(signature[64] as i32)?)?; - let pubkey = context.recover(&SecpMessage::from_slice(&message[..])?, &rsig)?; + let pubkey = &SECP256K1.recover(&SecpMessage::from_slice(&message[..])?, &rsig)?; let serialized = pubkey.serialize_uncompressed(); - let mut public = Public::default(); public.as_bytes_mut().copy_from_slice(&serialized[1..65]); Ok(public) } +/// Recovers the public key from the signature for the given message. +/// This version of `recover()` allows for all-zero messages, which is necessary +/// for ethereum but is otherwise highly discouraged. Use with caution. +pub fn recover_allowing_all_zero_message( + signature: &Signature, + message: ZeroesAllowedMessage, +) -> Result { + let rsig = RecoverableSignature::from_compact(&signature[0..64], RecoveryId::from_i32(signature[64] as i32)?)?; + let pubkey = &SECP256K1.recover(&message.into(), &rsig)?; + let serialized = pubkey.serialize_uncompressed(); + let mut public = Public::zero(); + public.as_bytes_mut().copy_from_slice(&serialized[1..65]); + Ok(public) +} + #[cfg(test)] mod tests { - use super::super::{Generator, Message, Random}; - use super::{recover, sign, verify_address, verify_public, Signature}; + use super::super::{Generator, Message, Random, SECP256K1}; + use super::{ + recover, recover_allowing_all_zero_message, sign, verify_address, verify_public, Secret, Signature, + ZeroesAllowedMessage, + }; + use secp256k1::SecretKey; use std::str::FromStr; + // Copy of `sign()` that allows signing all-zero Messages. + // Note: this is for *tests* only. DO NOT USE UNLESS YOU NEED IT. + fn sign_zero_message(secret: &Secret) -> Signature { + let context = &SECP256K1; + let sec = SecretKey::from_slice(secret.as_ref()).unwrap(); + // force an all-zero message into a secp `Message` bypassing the validity check. + let zero_msg = ZeroesAllowedMessage(Message::zero()); + let s = context.sign_recoverable(&zero_msg.into(), &sec); + let (rec_id, data) = s.serialize_compact(); + let mut data_arr = [0; 65]; + + // no need to check if s is low, it always is + data_arr[0..64].copy_from_slice(&data[0..64]); + data_arr[64] = rec_id.to_i32() as u8; + Signature(data_arr) + } + #[test] fn vrs_conversion() { // given @@ -295,6 +329,22 @@ mod tests { assert_eq!(keypair.public(), &recover(&signature, &message).unwrap()); } + #[test] + fn sign_and_recover_public_fails_with_zeroed_messages() { + let keypair = Random.generate(); + let signature = sign_zero_message(keypair.secret()); + let zero_message = Message::zero(); + assert!(&recover(&signature, &zero_message).is_err()); + } + + #[test] + fn recover_allowing_all_zero_message_can_recover_from_all_zero_messages() { + let keypair = Random.generate(); + let signature = sign_zero_message(keypair.secret()); + let zero_message = ZeroesAllowedMessage(Message::zero()); + assert_eq!(keypair.public(), &recover_allowing_all_zero_message(&signature, zero_message).unwrap()) + } + #[test] fn sign_and_verify_public() { let keypair = Random.generate(); diff --git a/parity-crypto/src/publickey/mod.rs b/parity-crypto/src/publickey/mod.rs index 294d67b38..53dd12209 100644 --- a/parity-crypto/src/publickey/mod.rs +++ b/parity-crypto/src/publickey/mod.rs @@ -20,7 +20,9 @@ pub mod ecdh; pub mod ecies; pub mod error; -pub use self::ecdsa_signature::{recover, sign, verify_address, verify_public, Signature}; +pub use self::ecdsa_signature::{ + recover, recover_allowing_all_zero_message, sign, verify_address, verify_public, Signature, +}; pub use self::error::Error; pub use self::extended_keys::{Derivation, DerivationError, ExtendedKeyPair, ExtendedPublic, ExtendedSecret}; pub use self::keypair::{public_to_address, KeyPair}; @@ -33,6 +35,22 @@ use lazy_static::lazy_static; pub use ethereum_types::{Address, Public}; pub type Message = H256; +use secp256k1::ThirtyTwoByteHash; + +/// In ethereum we allow public key recovery from a signature + message pair +/// where the message is all-zeroes. This conflicts with the best practise of +/// not allowing such values and so in order to avoid breaking consensus we need +/// this to work around it. The `ZeroesAllowedType` wraps an `H256` that can be +/// converted to a `[u8; 32]` which in turn can be cast to a +/// `secp256k1::Message` by the `ThirtyTwoByteHash` and satisfy the API for +/// `recover()`. +pub struct ZeroesAllowedMessage(H256); +impl ThirtyTwoByteHash for ZeroesAllowedMessage { + fn into_32(self) -> [u8; 32] { + self.0.to_fixed_bytes() + } +} + /// The number -1 encoded as a secret key const MINUS_ONE_KEY: &'static [u8] = &[ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xba, 0xae, 0xdc, From 0424206b9f022d4befaa71d03ddbc65859edcd9b Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 10 Apr 2020 16:57:38 +0200 Subject: [PATCH 43/56] keccak-hash: add keccak256_range and keccak512_range functions (#370) * keccak-hash: add keccak256_range and keccak512_range functions * keccak-hash: prep for release * keccak-hash: update the date in changelog * keccak-hash: more docs * Update keccak-hash/src/lib.rs Co-Authored-By: David Co-authored-by: David --- keccak-hash/CHANGELOG.md | 6 ++++- keccak-hash/src/lib.rs | 51 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/keccak-hash/CHANGELOG.md b/keccak-hash/CHANGELOG.md index 13f73c4a9..e8580f5d2 100644 --- a/keccak-hash/CHANGELOG.md +++ b/keccak-hash/CHANGELOG.md @@ -6,9 +6,13 @@ The format is based on [Keep a Changelog]. ## [Unreleased] -## [0.4.2] - 2020-03-16 +## [0.5.1] - 2020-04-10 +- Added `keccak256_range` and `keccak512_range` functions. [#370](https://github.com/paritytech/parity-common/pull/370) + +## [0.5.0] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) - Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) +- Updated tiny-keccak. [#260](https://github.com/paritytech/parity-common/pull/260) ## [0.4.1] - 2019-10-24 ### Dependencies diff --git a/keccak-hash/src/lib.rs b/keccak-hash/src/lib.rs index e9f410672..dbad92af5 100644 --- a/keccak-hash/src/lib.rs +++ b/keccak-hash/src/lib.rs @@ -45,6 +45,32 @@ pub fn keccak256(data: &mut [u8]) { keccak256.finalize(data); } +/// Computes in-place keccak256 hash of `data[range]`. +/// +/// The `range` argument specifies a subslice of `data` in bytes to be hashed. +/// The resulting hash will be written back to `data`. +/// # Panics +/// +/// If `range` is out of bounds. +/// +/// # Example +/// +/// ``` +/// let mut data = [1u8; 32]; +/// // Hash the first 8 bytes of `data` and write the result, 32 bytes, to `data`. +/// keccak_hash::keccak256_range(&mut data, 0..8); +/// let expected = [ +/// 0x54, 0x84, 0x4f, 0x69, 0xb4, 0xda, 0x4b, 0xb4, 0xa9, 0x9f, 0x24, 0x59, 0xb5, 0x11, 0xd4, 0x42, +/// 0xcc, 0x5b, 0xd2, 0xfd, 0xf4, 0xc3, 0x54, 0xd2, 0x07, 0xbb, 0x13, 0x08, 0x94, 0x43, 0xaf, 0x68, +/// ]; +/// assert_eq!(&data, &expected); +/// ``` +pub fn keccak256_range(data: &mut [u8], range: core::ops::Range) { + let mut keccak256 = Keccak::v256(); + keccak256.update(&data[range]); + keccak256.finalize(data); +} + /// Computes in-place keccak512 hash of `data`. pub fn keccak512(data: &mut [u8]) { let mut keccak512 = Keccak::v512(); @@ -52,6 +78,31 @@ pub fn keccak512(data: &mut [u8]) { keccak512.finalize(data); } +/// Computes in-place keccak512 hash of `data[range]`. +/// +/// The `range` argument specifies a subslice of `data` in bytes to be hashed. +/// The resulting hash will be written back to `data`. +/// # Panics +/// +/// If `range` is out of bounds. +/// +/// # Example +/// +/// ``` +/// let mut data = [1u8; 64]; +/// keccak_hash::keccak512_range(&mut data, 0..8); +/// let expected = [ +/// 0x90, 0x45, 0xc5, 0x9e, 0xd3, 0x0e, 0x1f, 0x42, 0xac, 0x35, 0xcc, 0xc9, 0x55, 0x7c, 0x77, 0x17, +/// 0xc8, 0x89, 0x3a, 0x77, 0x6c, 0xea, 0x2e, 0xf3, 0x88, 0xea, 0xe5, 0xc0, 0xea, 0x40, 0x26, 0x64, +/// ]; +/// assert_eq!(&data[..32], &expected); +/// ``` +pub fn keccak512_range(data: &mut [u8], range: core::ops::Range) { + let mut keccak512 = Keccak::v512(); + keccak512.update(&data[range]); + keccak512.finalize(data); +} + pub fn keccak_256(input: &[u8], output: &mut [u8]) { write_keccak(input, output); } From 53b47b778d5116397c51300f5ddb1030a83dc510 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Fri, 10 Apr 2020 17:27:04 +0200 Subject: [PATCH 44/56] keccak-hash: bump version to 0.5.1 (#371) --- keccak-hash/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keccak-hash/Cargo.toml b/keccak-hash/Cargo.toml index ea36f7288..54c1c0439 100644 --- a/keccak-hash/Cargo.toml +++ b/keccak-hash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "keccak-hash" -version = "0.5.0" +version = "0.5.1" description = "`keccak-hash` is a set of utility functions to facilitate working with Keccak hashes (256/512 bits long)." authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" From 13ae5bebe24d5c103340a5394da4a3e1f2109203 Mon Sep 17 00:00:00 2001 From: David Date: Sat, 11 Apr 2020 22:57:34 +0200 Subject: [PATCH 45/56] [parity-crypto] Release 0.6.1 (#373) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …and fix construction of `ZeroesAllowedMessage` --- parity-crypto/CHANGELOG.md | 3 +++ parity-crypto/Cargo.toml | 2 +- parity-crypto/src/publickey/mod.rs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/parity-crypto/CHANGELOG.md b/parity-crypto/CHANGELOG.md index 14290d54d..08cd46532 100644 --- a/parity-crypto/CHANGELOG.md +++ b/parity-crypto/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.6.1] - 2020-04-11 +- Add `recover_allowing_all_zero_message()` and `ZeroesAllowedMessage` to accomodate ethereum's `ecrecover` builtin. [#369](https://github.com/paritytech/parity-common/pull/369) + ## [0.6.0] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) - Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) diff --git a/parity-crypto/Cargo.toml b/parity-crypto/Cargo.toml index 763fc4b74..1b1944ad3 100644 --- a/parity-crypto/Cargo.toml +++ b/parity-crypto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parity-crypto" -version = "0.6.0" +version = "0.6.1" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Crypto utils used by ethstore and network." diff --git a/parity-crypto/src/publickey/mod.rs b/parity-crypto/src/publickey/mod.rs index 53dd12209..54d3ffe79 100644 --- a/parity-crypto/src/publickey/mod.rs +++ b/parity-crypto/src/publickey/mod.rs @@ -44,7 +44,7 @@ use secp256k1::ThirtyTwoByteHash; /// converted to a `[u8; 32]` which in turn can be cast to a /// `secp256k1::Message` by the `ThirtyTwoByteHash` and satisfy the API for /// `recover()`. -pub struct ZeroesAllowedMessage(H256); +pub struct ZeroesAllowedMessage(pub H256); impl ThirtyTwoByteHash for ZeroesAllowedMessage { fn into_32(self) -> [u8; 32] { self.0.to_fixed_bytes() From 0bba5668615e88aec23d2d2e22f7b5bae6e0932b Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Sat, 11 Apr 2020 22:59:00 +0200 Subject: [PATCH 46/56] keccak-hash: fix bench and add one for range (#372) * keccak-hash: fix bench and add one for range * fmt --- .travis.yml | 2 +- keccak-hash/Cargo.toml | 4 ++++ keccak-hash/benches/keccak_256.rs | 18 ++++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 19c6b18ef..53e552f6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ script: cargo fmt -- --check; fi - cargo check --workspace --tests --benches - - cargo test --all --exclude uint --exclude fixed-hash --exclude parity-crypto + - cargo test --workspace --exclude uint --exclude fixed-hash --exclude parity-crypto - if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cd contract-address/ && cargo test --features=external_doc && cd ..; fi diff --git a/keccak-hash/Cargo.toml b/keccak-hash/Cargo.toml index 54c1c0439..c663c66c5 100644 --- a/keccak-hash/Cargo.toml +++ b/keccak-hash/Cargo.toml @@ -19,3 +19,7 @@ criterion = "0.3.0" [features] default = ["std"] std = [] + +[[bench]] +name = "keccak_256" +harness = false diff --git a/keccak-hash/benches/keccak_256.rs b/keccak-hash/benches/keccak_256.rs index 97e9ee13d..3a28f993a 100644 --- a/keccak-hash/benches/keccak_256.rs +++ b/keccak-hash/benches/keccak_256.rs @@ -22,12 +22,26 @@ pub fn keccak_256_with_empty_input(c: &mut Criterion) { } pub fn keccak_256_with_typical_input(c: &mut Criterion) { - let data: Vec = From::from("some medium length string with important information"); - c.bench_function("keccak_256_with_typical_input", |b| { + let mut data: Vec = From::from("some medium length string with important information"); + let len = data.len(); + let mut group = c.benchmark_group("keccak_256_with_typical_input"); + group.bench_function("regular", |b| { b.iter(|| { let _out = keccak(black_box(&data)); }) }); + group.bench_function("inplace", |b| { + b.iter(|| { + keccak_hash::keccak256(black_box(&mut data[..])); + }) + }); + group.bench_function("inplace_range", |b| { + b.iter(|| { + keccak_hash::keccak256_range(black_box(&mut data[..]), 0..len); + }) + }); + + group.finish(); } pub fn keccak_256_with_large_input(c: &mut Criterion) { From ef69ef1dcda806a45b1988605bf71843dd032cc1 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Wed, 15 Apr 2020 00:11:34 +0200 Subject: [PATCH 47/56] parity-util-mem: fix for windows (#375) * parity-util-mem: try to fix compilation on windows * appveyor: test parity-util-mem with no-std * appveyor: test parity-util-mem with default features * fmt --- appveyor.yml | 2 ++ parity-util-mem/src/allocators.rs | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index bc9c9bf75..2807de0d7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -26,4 +26,6 @@ test_script: - cd fixed-hash/ && cargo test --all-features && cd .. - cd uint/ && cargo test --features=std,quickcheck --release && cd .. - cd plain_hasher/ && cargo test --no-default-features && cd .. + - cd parity-util-mem/ && cargo test --no-default-features && cd .. - cd parity-util-mem/ && cargo test --features=estimate-heapsize && cd .. + - cd parity-util-mem/ && cargo test && cd .. diff --git a/parity-util-mem/src/allocators.rs b/parity-util-mem/src/allocators.rs index 8d8bb18db..fca674ebe 100644 --- a/parity-util-mem/src/allocators.rs +++ b/parity-util-mem/src/allocators.rs @@ -66,6 +66,7 @@ mod usable_size { } else if #[cfg(target_os = "windows")] { use winapi::um::heapapi::{GetProcessHeap, HeapSize, HeapValidate}; + use winapi::ctypes::c_void as winapi_c_void; /// Get the size of a heap block. /// Call windows allocator through `winapi` crate @@ -73,11 +74,11 @@ mod usable_size { let heap = GetProcessHeap(); - if HeapValidate(heap, 0, ptr) == 0 { + if HeapValidate(heap, 0, ptr as *const winapi_c_void) == 0 { ptr = *(ptr as *const *const c_void).offset(-1); } - HeapSize(heap, 0, ptr) as usize + HeapSize(heap, 0, ptr as *const winapi_c_void) as usize } } else if #[cfg(feature = "jemalloc-global")] { From b99e466e60d19c298b54f593bbd2266edca7f61f Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Wed, 15 Apr 2020 10:41:19 +0200 Subject: [PATCH 48/56] bump parity-util-mem (#376) * parity-util-mem: bump minor version * parity-util-mem: update the changelog * parity-util-mem: update README --- parity-util-mem/CHANGELOG.md | 4 +++- parity-util-mem/Cargo.toml | 2 +- parity-util-mem/README.md | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/parity-util-mem/CHANGELOG.md b/parity-util-mem/CHANGELOG.md index ec8ef91f9..a23c2164d 100644 --- a/parity-util-mem/CHANGELOG.md +++ b/parity-util-mem/CHANGELOG.md @@ -5,7 +5,9 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] -### Breaking + +## [0.6.1] - 2020-04-15 +- Fix compilation on Windows for no-std. [#375](https://github.com/paritytech/parity-common/pull/375) - Prevent multiple versions from being linked into the same program. [#363](https://github.com/paritytech/parity-common/pull/363) ## [0.6.0] - 2020-03-13 diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index 700061c32..97e20cf0e 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parity-util-mem" -version = "0.6.0" +version = "0.6.1" authors = ["Parity Technologies "] repository = "https://github.com/paritytech/parity-common" description = "Collection of memory related utilities" diff --git a/parity-util-mem/README.md b/parity-util-mem/README.md index a6f15b90b..8b7dd7bd1 100644 --- a/parity-util-mem/README.md +++ b/parity-util-mem/README.md @@ -9,8 +9,8 @@ it must be the sole place where a global allocator is defined. The only exception to this rule is when used in a `no_std` context or when the `estimate-heapsize` feature is used. Because of that, it must be present in the dependency tree with a single version. -Starting from version 0.7, having duplicate versions of `parity-util-mem` will lead -to a compile-time error. It still will be possible to have 0.6 and 0.7 versions in the same binary though. +Starting from version 0.6.1, having duplicate versions of `parity-util-mem` will lead +to a compile-time error. It still will be possible to have 0.5 and 0.6.1 versions in the same binary though. Unless heeded you risk UB; see discussion in [issue 364]. From a52fbeb0c8f0f77b418abb8a70b5ff7e83ce49eb Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Wed, 15 Apr 2020 10:45:21 +0200 Subject: [PATCH 49/56] kvdb-rocksdb: optimize and rename iter_from_prefix (#365) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * kvdb: small cleanup * kvdb-rocksdb: rename and optimize iter_with_prefix * fix links in changelogs * apply suggestions from code review * 🤦 * fmt --- kvdb-memorydb/src/lib.rs | 6 +++--- kvdb-rocksdb/CHANGELOG.md | 1 + kvdb-rocksdb/src/iter.rs | 28 +++++++++++++++++++--------- kvdb-rocksdb/src/lib.rs | 36 ++++++++++++++++++++++-------------- kvdb-shared-tests/src/lib.rs | 18 +++++++++--------- kvdb-web/src/lib.rs | 4 ++-- kvdb-web/tests/indexed_db.rs | 6 +++--- kvdb/CHANGELOG.md | 2 ++ kvdb/src/lib.rs | 8 +++++--- 9 files changed, 66 insertions(+), 43 deletions(-) diff --git a/kvdb-memorydb/src/lib.rs b/kvdb-memorydb/src/lib.rs index c37ed821f..6a70babea 100644 --- a/kvdb-memorydb/src/lib.rs +++ b/kvdb-memorydb/src/lib.rs @@ -97,7 +97,7 @@ impl KeyValueDB for InMemory { } } - fn iter_from_prefix<'a>( + fn iter_with_prefix<'a>( &'a self, col: u32, prefix: &'a [u8], @@ -155,9 +155,9 @@ mod tests { } #[test] - fn iter_from_prefix() -> io::Result<()> { + fn iter_with_prefix() -> io::Result<()> { let db = create(1); - st::test_iter_from_prefix(&db) + st::test_iter_with_prefix(&db) } #[test] diff --git a/kvdb-rocksdb/CHANGELOG.md b/kvdb-rocksdb/CHANGELOG.md index 43cf44408..cd4838404 100644 --- a/kvdb-rocksdb/CHANGELOG.md +++ b/kvdb-rocksdb/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog]. ## [Unreleased] ### Breaking - Updated to the new `kvdb` interface. [#313](https://github.com/paritytech/parity-common/pull/313) +- Rename and optimize prefix iteration. [#365](https://github.com/paritytech/parity-common/pull/365) ## [0.7.0] - 2020-03-16 - Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) diff --git a/kvdb-rocksdb/src/iter.rs b/kvdb-rocksdb/src/iter.rs index 71482f446..a1ef70a53 100644 --- a/kvdb-rocksdb/src/iter.rs +++ b/kvdb-rocksdb/src/iter.rs @@ -12,8 +12,7 @@ //! //! Note: this crate does not use "Prefix Seek" mode which means that the prefix iterator //! will return keys not starting with the given prefix as well (as long as `key >= prefix`). -//! To work around this we filter the data returned by rocksdb to ensure that -//! all data yielded by the iterator does start with the given prefix. +//! To work around this we set an upper bound to the prefix successor. //! See https://github.com/facebook/rocksdb/wiki/Prefix-Seek-API-Changes for details. use crate::DBAndColumns; @@ -28,6 +27,13 @@ pub type KeyValuePair = (Box<[u8]>, Box<[u8]>); /// Iterator with built-in synchronization. pub struct ReadGuardedIterator<'a, I, T> { inner: OwningHandle>, DerefWrapper>>, + // We store the upper bound here + // to make sure it lives at least as long as the iterator. + // See https://github.com/rust-rocksdb/rust-rocksdb/pull/309. + // TODO: remove this once https://github.com/rust-rocksdb/rust-rocksdb/pull/377 + // is merged and released. + #[allow(dead_code)] + upper_bound_prefix: Option>, } // We can't implement `StableAddress` for a `RwLockReadGuard` @@ -81,8 +87,8 @@ pub trait IterationHandler { /// Create an `Iterator` over a `ColumnFamily` corresponding to the passed index. Takes a /// reference to a `ReadOptions` to allow configuration of the new iterator (see /// https://github.com/facebook/rocksdb/blob/master/include/rocksdb/options.h#L1169). - /// The iterator starts from the first key having the provided `prefix`. - fn iter_from_prefix(&self, col: u32, prefix: &[u8], read_opts: &ReadOptions) -> Self::Iterator; + /// The `Iterator` iterates over keys which start with the provided `prefix`. + fn iter_with_prefix(&self, col: u32, prefix: &[u8], read_opts: &ReadOptions) -> Self::Iterator; } impl<'a, T> ReadGuardedIterator<'a, <&'a T as IterationHandler>::Iterator, T> @@ -92,18 +98,22 @@ where /// Creates a new `ReadGuardedIterator` that maps `RwLock` to `RwLock`, /// where `DBIterator` iterates over all keys. pub fn new(read_lock: RwLockReadGuard<'a, Option>, col: u32, read_opts: &ReadOptions) -> Self { - Self { inner: Self::new_inner(read_lock, |db| db.iter(col, read_opts)) } + Self { inner: Self::new_inner(read_lock, |db| db.iter(col, read_opts)), upper_bound_prefix: None } } /// Creates a new `ReadGuardedIterator` that maps `RwLock` to `RwLock`, - /// where `DBIterator` iterates over keys >= prefix. - pub fn new_from_prefix( + /// where `DBIterator` iterates over keys which start with the given prefix. + pub fn new_with_prefix( read_lock: RwLockReadGuard<'a, Option>, col: u32, prefix: &[u8], + upper_bound: Box<[u8]>, read_opts: &ReadOptions, ) -> Self { - Self { inner: Self::new_inner(read_lock, |db| db.iter_from_prefix(col, prefix, read_opts)) } + Self { + inner: Self::new_inner(read_lock, |db| db.iter_with_prefix(col, prefix, read_opts)), + upper_bound_prefix: Some(upper_bound), + } } fn new_inner( @@ -126,7 +136,7 @@ impl<'a> IterationHandler for &'a DBAndColumns { .expect("iterator params are valid; qed") } - fn iter_from_prefix(&self, col: u32, prefix: &[u8], read_opts: &ReadOptions) -> Self::Iterator { + fn iter_with_prefix(&self, col: u32, prefix: &[u8], read_opts: &ReadOptions) -> Self::Iterator { self.db .iterator_cf_opt(self.cf(col as usize), read_opts, IteratorMode::From(prefix, Direction::Forward)) .expect("iterator params are valid; qed") diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index 54a81140c..72c96f540 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -444,13 +444,13 @@ impl Database { batch.delete_cf(cf, &key).map_err(other_io_err)? } DBOp::DeletePrefix { col: _, prefix } => { - if prefix.len() > 0 { + if !prefix.is_empty() { let end_range = kvdb::end_prefix(&prefix[..]); batch.delete_range_cf(cf, &prefix[..], &end_range[..]).map_err(other_io_err)?; } else { // Deletes all values in the column. let end_range = &[u8::max_value()]; - batch.delete_range_cf(cf, &prefix[..], &end_range[..]).map_err(other_io_err)?; + batch.delete_range_cf(cf, &[][..], &end_range[..]).map_err(other_io_err)?; batch.delete_cf(cf, &end_range[..]).map_err(other_io_err)?; } } @@ -492,7 +492,7 @@ impl Database { /// Get value by partial key. Prefix size should match configured prefix size. pub fn get_by_prefix(&self, col: u32, prefix: &[u8]) -> Option> { - self.iter_from_prefix(col, prefix).next().map(|(_, v)| v) + self.iter_with_prefix(col, prefix).next().map(|(_, v)| v) } /// Iterator over the data in the given database column index. @@ -512,18 +512,26 @@ impl Database { /// Iterator over data in the `col` database column index matching the given prefix. /// Will hold a lock until the iterator is dropped /// preventing the database from being closed. - fn iter_from_prefix<'a>(&'a self, col: u32, prefix: &'a [u8]) -> impl Iterator + 'a { + fn iter_with_prefix<'a>(&'a self, col: u32, prefix: &'a [u8]) -> impl Iterator + 'a { let read_lock = self.db.read(); let optional = if read_lock.is_some() { - let guarded = iter::ReadGuardedIterator::new_from_prefix(read_lock, col, prefix, &self.read_opts); + let mut read_opts = ReadOptions::default(); + read_opts.set_verify_checksums(false); + let end_prefix = kvdb::end_prefix(prefix).into_boxed_slice(); + // rocksdb doesn't work with an empty upper bound + if !end_prefix.is_empty() { + // SAFETY: the end_prefix lives as long as the iterator + // See `ReadGuardedIterator` definition for more details. + unsafe { + read_opts.set_iterate_upper_bound(&end_prefix); + } + } + let guarded = iter::ReadGuardedIterator::new_with_prefix(read_lock, col, prefix, end_prefix, &read_opts); Some(guarded) } else { None }; - // We're not using "Prefix Seek" mode, so the iterator will return - // keys not starting with the given prefix as well, - // see https://github.com/facebook/rocksdb/wiki/Prefix-Seek-API-Changes - optional.into_iter().flat_map(identity).take_while(move |(k, _)| k.starts_with(prefix)) + optional.into_iter().flat_map(identity) } /// Close the database @@ -648,8 +656,8 @@ impl KeyValueDB for Database { Box::new(unboxed.into_iter()) } - fn iter_from_prefix<'a>(&'a self, col: u32, prefix: &'a [u8]) -> Box + 'a> { - let unboxed = Database::iter_from_prefix(self, col, prefix); + fn iter_with_prefix<'a>(&'a self, col: u32, prefix: &'a [u8]) -> Box + 'a> { + let unboxed = Database::iter_with_prefix(self, col, prefix); Box::new(unboxed.into_iter()) } @@ -729,9 +737,9 @@ mod tests { } #[test] - fn iter_from_prefix() -> io::Result<()> { + fn iter_with_prefix() -> io::Result<()> { let db = create(1)?; - st::test_iter_from_prefix(&db) + st::test_iter_with_prefix(&db) } #[test] @@ -742,7 +750,7 @@ mod tests { #[test] fn stats() -> io::Result<()> { - let db = create(st::IOSTATS_NUM_COLUMNS)?; + let db = create(st::IO_STATS_NUM_COLUMNS)?; st::test_io_stats(&db) } diff --git a/kvdb-shared-tests/src/lib.rs b/kvdb-shared-tests/src/lib.rs index 2ffcc07ef..76fb00c5c 100644 --- a/kvdb-shared-tests/src/lib.rs +++ b/kvdb-shared-tests/src/lib.rs @@ -80,8 +80,8 @@ pub fn test_iter(db: &dyn KeyValueDB) -> io::Result<()> { Ok(()) } -/// A test for `KeyValueDB::iter_from_prefix`. -pub fn test_iter_from_prefix(db: &dyn KeyValueDB) -> io::Result<()> { +/// A test for `KeyValueDB::iter_with_prefix`. +pub fn test_iter_with_prefix(db: &dyn KeyValueDB) -> io::Result<()> { let key1 = b"0"; let key2 = b"ab"; let key3 = b"abc"; @@ -95,7 +95,7 @@ pub fn test_iter_from_prefix(db: &dyn KeyValueDB) -> io::Result<()> { db.write(batch)?; // empty prefix - let contents: Vec<_> = db.iter_from_prefix(0, b"").into_iter().collect(); + let contents: Vec<_> = db.iter_with_prefix(0, b"").into_iter().collect(); assert_eq!(contents.len(), 4); assert_eq!(&*contents[0].0, key1); assert_eq!(&*contents[1].0, key2); @@ -103,31 +103,31 @@ pub fn test_iter_from_prefix(db: &dyn KeyValueDB) -> io::Result<()> { assert_eq!(&*contents[3].0, key4); // prefix a - let contents: Vec<_> = db.iter_from_prefix(0, b"a").into_iter().collect(); + let contents: Vec<_> = db.iter_with_prefix(0, b"a").into_iter().collect(); assert_eq!(contents.len(), 3); assert_eq!(&*contents[0].0, key2); assert_eq!(&*contents[1].0, key3); assert_eq!(&*contents[2].0, key4); // prefix abc - let contents: Vec<_> = db.iter_from_prefix(0, b"abc").into_iter().collect(); + let contents: Vec<_> = db.iter_with_prefix(0, b"abc").into_iter().collect(); assert_eq!(contents.len(), 2); assert_eq!(&*contents[0].0, key3); assert_eq!(&*contents[1].0, key4); // prefix abcde - let contents: Vec<_> = db.iter_from_prefix(0, b"abcde").into_iter().collect(); + let contents: Vec<_> = db.iter_with_prefix(0, b"abcde").into_iter().collect(); assert_eq!(contents.len(), 0); // prefix 0 - let contents: Vec<_> = db.iter_from_prefix(0, b"0").into_iter().collect(); + let contents: Vec<_> = db.iter_with_prefix(0, b"0").into_iter().collect(); assert_eq!(contents.len(), 1); assert_eq!(&*contents[0].0, key1); Ok(()) } /// The number of columns required to run `test_io_stats`. -pub const IOSTATS_NUM_COLUMNS: u32 = 3; +pub const IO_STATS_NUM_COLUMNS: u32 = 3; /// A test for `KeyValueDB::io_stats`. /// Assumes that the `db` has at least 3 columns. @@ -256,7 +256,7 @@ pub fn test_complex(db: &dyn KeyValueDB) -> io::Result<()> { assert_eq!(contents[1].0.to_vec(), key2.to_vec()); assert_eq!(&*contents[1].1, b"dog"); - let mut prefix_iter = db.iter_from_prefix(0, b"04c0"); + let mut prefix_iter = db.iter_with_prefix(0, b"04c0"); assert_eq!(*prefix_iter.next().unwrap().1, b"caterpillar"[..]); assert_eq!(*prefix_iter.next().unwrap().1, b"beef"[..]); assert_eq!(*prefix_iter.next().unwrap().1, b"fish"[..]); diff --git a/kvdb-web/src/lib.rs b/kvdb-web/src/lib.rs index f0179c085..49540e35e 100644 --- a/kvdb-web/src/lib.rs +++ b/kvdb-web/src/lib.rs @@ -113,12 +113,12 @@ impl KeyValueDB for Database { } // NOTE: clones the whole db - fn iter_from_prefix<'a>( + fn iter_with_prefix<'a>( &'a self, col: u32, prefix: &'a [u8], ) -> Box, Box<[u8]>)> + 'a> { - self.in_memory.iter_from_prefix(col, prefix) + self.in_memory.iter_with_prefix(col, prefix) } // NOTE: not supported diff --git a/kvdb-web/tests/indexed_db.rs b/kvdb-web/tests/indexed_db.rs index e32d5ea18..2becc48f4 100644 --- a/kvdb-web/tests/indexed_db.rs +++ b/kvdb-web/tests/indexed_db.rs @@ -52,9 +52,9 @@ async fn iter() { } #[wasm_bindgen_test] -async fn iter_from_prefix() { - let db = open_db(1, "iter_from_prefix").await; - st::test_iter_from_prefix(&db).unwrap() +async fn iter_with_prefix() { + let db = open_db(1, "iter_with_prefix").await; + st::test_iter_with_prefix(&db).unwrap() } #[wasm_bindgen_test] diff --git a/kvdb/CHANGELOG.md b/kvdb/CHANGELOG.md index 6cfa99a6e..62771e4dc 100644 --- a/kvdb/CHANGELOG.md +++ b/kvdb/CHANGELOG.md @@ -7,6 +7,8 @@ The format is based on [Keep a Changelog]. ## [Unreleased] ### Breaking - Removed `write_buffered` and `flush` methods. [#313](https://github.com/paritytech/parity-common/pull/313) +- Introduce a new `DeletePrefix` database operation. [#360](https://github.com/paritytech/parity-common/pull/360) +- Rename prefix iteration to `iter_with_prefix`. [#365](https://github.com/paritytech/parity-common/pull/365) ## [0.5.0] - 2020-03-16 - License changed from GPL3 to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) diff --git a/kvdb/src/lib.rs b/kvdb/src/lib.rs index 695519f43..a9c74e949 100644 --- a/kvdb/src/lib.rs +++ b/kvdb/src/lib.rs @@ -86,7 +86,7 @@ impl DBTransaction { /// Delete all values with the given key prefix. /// Using an empty prefix here will remove all keys - /// (all keys starts with the empty prefix). + /// (all keys start with the empty prefix). pub fn delete_prefix(&mut self, col: u32, prefix: &[u8]) { self.ops.push(DBOp::DeletePrefix { col, prefix: DBKey::from_slice(prefix) }); } @@ -119,8 +119,9 @@ pub trait KeyValueDB: Sync + Send + parity_util_mem::MallocSizeOf { /// Iterate over the data for a given column. fn iter<'a>(&'a self, col: u32) -> Box, Box<[u8]>)> + 'a>; - /// Iterate over the data for a given column, starting from a given prefix. - fn iter_from_prefix<'a>( + /// Iterate over the data for a given column, returning all key/value pairs + /// where the key starts with the given prefix. + fn iter_with_prefix<'a>( &'a self, col: u32, prefix: &'a [u8], @@ -170,6 +171,7 @@ mod test { assert_eq!(end_prefix(&[0x00, 0xff]), vec![0x01]); assert_eq!(end_prefix(&[0xff]), vec![]); + assert_eq!(end_prefix(b"0"), b"1".to_vec()); assert_eq!(end_prefix(&[]), vec![]); } } From 6bb24f26bc0d33c2d8556ef1048c13210f189a26 Mon Sep 17 00:00:00 2001 From: Kirk Baird Date: Thu, 23 Apr 2020 23:06:38 +1000 Subject: [PATCH 50/56] Add arbitrary trait implementation (#378) * Add arbitrary trait implementation Signed-off-by: Kirk Baird * Add arbitrary trait to Ethereum Types Signed-off-by: Kirk Baird * Tidy up creation of empty array Signed-off-by: Kirk Baird * Resolve minor issues Signed-off-by: Kirk Baird * Update README.md and fix features Signed-off-by: Kirk Baird * Add arbitrary support for Uint, ethbool and primitive-types Signed-off-by: Kirk Baird * Update add ethbloom/arbitrary Co-Authored-By: Andronik Ordian * Update uint/README.md Co-Authored-By: David * Rewrite arbitrary comments Signed-off-by: Kirk Baird * Update fixed-hash/src/hash.rs Co-Authored-By: David * Update fixed-hash/src/hash.rs Co-Authored-By: David Co-authored-by: Andronik Ordian Co-authored-by: David --- ethbloom/Cargo.toml | 1 + ethereum-types/Cargo.toml | 1 + fixed-hash/Cargo.toml | 1 + fixed-hash/README.md | 2 ++ fixed-hash/src/hash.rs | 37 +++++++++++++++++++++++++++++++++++++ fixed-hash/src/lib.rs | 4 ++++ primitive-types/Cargo.toml | 1 + uint/Cargo.toml | 1 + uint/README.md | 2 ++ uint/src/lib.rs | 4 ++++ uint/src/uint.rs | 24 ++++++++++++++++++++++++ 11 files changed, 78 insertions(+) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 038378a64..1f2de0a62 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -26,6 +26,7 @@ default = ["std", "serialize", "rustc-hex"] std = ["fixed-hash/std", "crunchy/std"] serialize = ["std", "impl-serde"] rustc-hex = ["fixed-hash/rustc-hex"] +arbitrary = ["fixed-hash/arbitrary"] [[bench]] name = "bloom" diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index b04c87bbd..8d9dc0739 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -22,3 +22,4 @@ serde_json = "1.0.41" 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"] diff --git a/fixed-hash/Cargo.toml b/fixed-hash/Cargo.toml index 93903ef7d..33fd076a0 100644 --- a/fixed-hash/Cargo.toml +++ b/fixed-hash/Cargo.toml @@ -19,6 +19,7 @@ quickcheck = { version = "0.9.0", optional = true } rand = { version = "0.7.2", optional = true, default-features = false } rustc-hex = { version = "2.0.1", optional = true, default-features = false } static_assertions = "1.0.0" +arbitrary = { version = "0.4", optional = true } [dev-dependencies] rand_xorshift = "0.2.0" diff --git a/fixed-hash/README.md b/fixed-hash/README.md index c07db2f23..1974bea8f 100644 --- a/fixed-hash/README.md +++ b/fixed-hash/README.md @@ -64,3 +64,5 @@ fixed-hash = { version = "0.3", default-features = false } - Disabled by default. - `api-dummy`: Generate a dummy hash type for API documentation. - Enabled by default at `docs.rs` +- `arbitrary`: Allow for creation of a hash from random unstructured input. + - Disabled by default. diff --git a/fixed-hash/src/hash.rs b/fixed-hash/src/hash.rs index e7fdf0e4c..972b750b4 100644 --- a/fixed-hash/src/hash.rs +++ b/fixed-hash/src/hash.rs @@ -316,6 +316,7 @@ macro_rules! construct_fixed_hash { impl_cmp_for_fixed_hash!($name); impl_rustc_hex_for_fixed_hash!($name); impl_quickcheck_for_fixed_hash!($name); + impl_arbitrary_for_fixed_hash!($name); } } @@ -636,6 +637,42 @@ macro_rules! impl_quickcheck_for_fixed_hash { }; } +// When the `arbitrary` feature is disabled. +// +// # Note +// +// Feature guarded macro definitions instead of feature guarded impl blocks +// to work around the problems of introducing `arbitrary` crate feature in +// a user crate. +#[cfg(not(feature = "arbitrary"))] +#[macro_export] +#[doc(hidden)] +macro_rules! impl_arbitrary_for_fixed_hash { + ( $name:ident ) => {}; +} + +// When the `arbitrary` feature is enabled. +// +// # Note +// +// Feature guarded macro definitions instead of feature guarded impl blocks +// to work around the problems of introducing `arbitrary` crate feature in +// a user crate. +#[cfg(feature = "arbitrary")] +#[macro_export] +#[doc(hidden)] +macro_rules! impl_arbitrary_for_fixed_hash { + ( $name:ident ) => { + impl $crate::arbitrary::Arbitrary for $name { + fn arbitrary(u: &mut $crate::arbitrary::Unstructured<'_>) -> $crate::arbitrary::Result { + let mut res = Self::zero(); + u.fill_buffer(&mut res.0)?; + Ok(Self::from(res)) + } + } + }; +} + #[macro_export] #[doc(hidden)] macro_rules! impl_ops_for_hash { diff --git a/fixed-hash/src/lib.rs b/fixed-hash/src/lib.rs index 748101c9f..228f551e0 100644 --- a/fixed-hash/src/lib.rs +++ b/fixed-hash/src/lib.rs @@ -46,6 +46,10 @@ pub use rand; #[doc(hidden)] pub use quickcheck; +#[cfg(feature = "arbitrary")] +#[doc(hidden)] +pub use arbitrary; + #[macro_use] mod hash; diff --git a/primitive-types/Cargo.toml b/primitive-types/Cargo.toml index 06e6e154d..fcbdc4e63 100644 --- a/primitive-types/Cargo.toml +++ b/primitive-types/Cargo.toml @@ -22,3 +22,4 @@ rustc-hex = ["fixed-hash/rustc-hex"] serde = ["std", "impl-serde"] codec = ["impl-codec"] rlp = ["impl-rlp"] +arbitrary = ["fixed-hash/arbitrary", "uint/arbitrary"] diff --git a/uint/Cargo.toml b/uint/Cargo.toml index 257b3fa7f..97d489884 100644 --- a/uint/Cargo.toml +++ b/uint/Cargo.toml @@ -16,6 +16,7 @@ qc = { package = "quickcheck", version = "0.9.0", optional = true } rand = { version = "0.7.2", default-features = false, optional = true } rustc-hex = { version = "2.0.1", default-features = false } static_assertions = "1.0.0" +arbitrary = { version = "0.4", optional = true } [features] default = ["std"] diff --git a/uint/README.md b/uint/README.md index 557d63991..34006f83d 100644 --- a/uint/README.md +++ b/uint/README.md @@ -69,3 +69,5 @@ see fuzz [README.md](fuzz/README.md) - Enabled by default. - `quickcheck`: Enable quickcheck-style property testing - Use with `cargo test --release --features=quickcheck`. +- `arbitrary`: Allow for creation of an `uint` object from random unstructured input for use with fuzzers that use the `arbitrary` crate. + - Disabled by default. diff --git a/uint/src/lib.rs b/uint/src/lib.rs index 144c53e32..7da1f24a5 100644 --- a/uint/src/lib.rs +++ b/uint/src/lib.rs @@ -29,6 +29,10 @@ pub use qc; #[doc(hidden)] pub use rand; +#[cfg(feature = "arbitrary")] +#[doc(hidden)] +pub use arbitrary; + #[doc(hidden)] pub use static_assertions; diff --git a/uint/src/uint.rs b/uint/src/uint.rs index 493e2e21e..26b633416 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -1554,6 +1554,7 @@ macro_rules! construct_uint { // `$n_words * 8` because macro expects bytes and // uints use 64 bit (8 byte) words $crate::impl_quickcheck_arbitrary_for_uint!($name, ($n_words * 8)); + $crate::impl_arbitrary_for_uint!($name, ($n_words * 8)); } } @@ -1632,3 +1633,26 @@ macro_rules! impl_quickcheck_arbitrary_for_uint { macro_rules! impl_quickcheck_arbitrary_for_uint { ($uint: ty, $n_bytes: tt) => {}; } + + +#[cfg(feature = "arbitrary")] +#[macro_export] +#[doc(hidden)] +macro_rules! impl_arbitrary_for_uint { + ($uint: ty, $n_bytes: tt) => { + impl $crate::arbitrary::Arbitrary for $uint { + fn arbitrary(u: &mut $crate::arbitrary::Unstructured<'_>) -> $crate::arbitrary::Result { + let mut res = [0u8; $n_bytes]; + u.fill_buffer(&mut res)?; + Ok(Self::from(res)) + } + } + }; +} + +#[cfg(not(feature = "arbitrary"))] +#[macro_export] +#[doc(hidden)] +macro_rules! impl_arbitrary_for_uint { + ($uint: ty, $n_bytes: tt) => {}; +} From 692aa9d9f25e0af9e44cfda15b1653f128168997 Mon Sep 17 00:00:00 2001 From: cheme Date: Thu, 23 Apr 2020 16:20:57 +0200 Subject: [PATCH 51/56] Fix limit prefix delete case (#368) * Fix limit prefix delete case. Warning this uses iter by prefix for it in rocksdb. * Comment * Changes needed for merging, end_prefix returning option in new code and renaming of iter with prefix. * reduce cornercase iteration windows size. * extract common iter prefix delete corner case code. * Update kvdb-rocksdb/src/lib.rs Co-Authored-By: Andronik Ordian * Remove unused code, there can be call to 'delete_range_cf' on empty range, but that is fine. Co-authored-by: Andronik Ordian --- kvdb-memorydb/src/lib.rs | 7 +++++-- kvdb-rocksdb/src/iter.rs | 4 ++-- kvdb-rocksdb/src/lib.rs | 26 ++++++++++++++------------ kvdb-shared-tests/src/lib.rs | 21 +++++++++++++-------- kvdb/src/lib.rs | 26 +++++++++++++++----------- 5 files changed, 49 insertions(+), 35 deletions(-) diff --git a/kvdb-memorydb/src/lib.rs b/kvdb-memorydb/src/lib.rs index 6a70babea..0ac955a0b 100644 --- a/kvdb-memorydb/src/lib.rs +++ b/kvdb-memorydb/src/lib.rs @@ -74,8 +74,11 @@ impl KeyValueDB for InMemory { col.clear(); } else { let start_range = Bound::Included(prefix.to_vec()); - let end_range = Bound::Excluded(kvdb::end_prefix(&prefix[..])); - let keys: Vec<_> = col.range((start_range, end_range)).map(|(k, _)| k.clone()).collect(); + let keys: Vec<_> = if let Some(end_range) = kvdb::end_prefix(&prefix[..]) { + col.range((start_range, Bound::Excluded(end_range))).map(|(k, _)| k.clone()).collect() + } else { + col.range((start_range, Bound::Unbounded)).map(|(k, _)| k.clone()).collect() + }; for key in keys.into_iter() { col.remove(&key[..]); } diff --git a/kvdb-rocksdb/src/iter.rs b/kvdb-rocksdb/src/iter.rs index a1ef70a53..62f9ba9a2 100644 --- a/kvdb-rocksdb/src/iter.rs +++ b/kvdb-rocksdb/src/iter.rs @@ -107,12 +107,12 @@ where read_lock: RwLockReadGuard<'a, Option>, col: u32, prefix: &[u8], - upper_bound: Box<[u8]>, + upper_bound: Option>, read_opts: &ReadOptions, ) -> Self { Self { inner: Self::new_inner(read_lock, |db| db.iter_with_prefix(col, prefix, read_opts)), - upper_bound_prefix: Some(upper_bound), + upper_bound_prefix: upper_bound, } } diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index 72c96f540..d4e76b4c8 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -443,15 +443,16 @@ impl Database { stats_total_bytes += key.len(); batch.delete_cf(cf, &key).map_err(other_io_err)? } - DBOp::DeletePrefix { col: _, prefix } => { - if !prefix.is_empty() { - let end_range = kvdb::end_prefix(&prefix[..]); - batch.delete_range_cf(cf, &prefix[..], &end_range[..]).map_err(other_io_err)?; - } else { - // Deletes all values in the column. - let end_range = &[u8::max_value()]; - batch.delete_range_cf(cf, &[][..], &end_range[..]).map_err(other_io_err)?; - batch.delete_cf(cf, &end_range[..]).map_err(other_io_err)?; + DBOp::DeletePrefix { col, prefix } => { + let end_prefix = kvdb::end_prefix(&prefix[..]); + let no_end = end_prefix.is_none(); + let end_range = end_prefix.unwrap_or_else(|| vec![u8::max_value(); 16]); + batch.delete_range_cf(cf, &prefix[..], &end_range[..]).map_err(other_io_err)?; + if no_end { + let prefix = if prefix.len() > end_range.len() { &prefix[..] } else { &end_range[..] }; + for (key, _) in self.iter_with_prefix(col, prefix) { + batch.delete_cf(cf, &key[..]).map_err(other_io_err)?; + } } } }; @@ -517,15 +518,16 @@ impl Database { let optional = if read_lock.is_some() { let mut read_opts = ReadOptions::default(); read_opts.set_verify_checksums(false); - let end_prefix = kvdb::end_prefix(prefix).into_boxed_slice(); // rocksdb doesn't work with an empty upper bound - if !end_prefix.is_empty() { + let end_prefix = kvdb::end_prefix(prefix).map(|end_prefix| { + let end_prefix = end_prefix.into_boxed_slice(); // SAFETY: the end_prefix lives as long as the iterator // See `ReadGuardedIterator` definition for more details. unsafe { read_opts.set_iterate_upper_bound(&end_prefix); } - } + end_prefix + }); let guarded = iter::ReadGuardedIterator::new_with_prefix(read_lock, col, prefix, end_prefix, &read_opts); Some(guarded) } else { diff --git a/kvdb-shared-tests/src/lib.rs b/kvdb-shared-tests/src/lib.rs index 76fb00c5c..f3352faa0 100644 --- a/kvdb-shared-tests/src/lib.rs +++ b/kvdb-shared-tests/src/lib.rs @@ -175,7 +175,7 @@ pub fn test_io_stats(db: &dyn KeyValueDB) -> io::Result<()> { } /// The number of columns required to run `test_delete_prefix`. -pub const DELETE_PREFIX_NUM_COLUMNS: u32 = 5; +pub const DELETE_PREFIX_NUM_COLUMNS: u32 = 7; /// A test for `KeyValueDB::delete_prefix`. pub fn test_delete_prefix(db: &dyn KeyValueDB) -> io::Result<()> { @@ -190,6 +190,7 @@ pub fn test_delete_prefix(db: &dyn KeyValueDB) -> io::Result<()> { &[2][..], &[2, 0][..], &[2, 255][..], + &[255; 16][..], ]; let init_db = |ix: u32| -> io::Result<()> { let mut batch = db.transaction(); @@ -199,8 +200,8 @@ pub fn test_delete_prefix(db: &dyn KeyValueDB) -> io::Result<()> { db.write(batch)?; Ok(()) }; - let check_db = |ix: u32, content: [bool; 10]| -> io::Result<()> { - let mut state = [true; 10]; + let check_db = |ix: u32, content: [bool; 11]| -> io::Result<()> { + let mut state = [true; 11]; for (c, key) in keys.iter().enumerate() { state[c] = db.get(ix, key)?.is_some(); } @@ -209,15 +210,19 @@ pub fn test_delete_prefix(db: &dyn KeyValueDB) -> io::Result<()> { }; let tests: [_; DELETE_PREFIX_NUM_COLUMNS as usize] = [ // standard - (&[1u8][..], [true, true, true, false, false, false, false, true, true, true]), + (&[1u8][..], [true, true, true, false, false, false, false, true, true, true, true]), // edge - (&[1u8, 255, 255][..], [true, true, true, true, true, true, false, true, true, true]), + (&[1u8, 255, 255][..], [true, true, true, true, true, true, false, true, true, true, true]), // none 1 - (&[1, 2][..], [true, true, true, true, true, true, true, true, true, true]), + (&[1, 2][..], [true, true, true, true, true, true, true, true, true, true, true]), // none 2 - (&[8][..], [true, true, true, true, true, true, true, true, true, true]), + (&[8][..], [true, true, true, true, true, true, true, true, true, true, true]), + // last value + (&[255, 255][..], [true, true, true, true, true, true, true, true, true, true, false]), + // last value, limit prefix + (&[255][..], [true, true, true, true, true, true, true, true, true, true, false]), // all - (&[][..], [false, false, false, false, false, false, false, false, false, false]), + (&[][..], [false, false, false, false, false, false, false, false, false, false, false]), ]; for (ix, test) in tests.iter().enumerate() { let ix = ix as u32; diff --git a/kvdb/src/lib.rs b/kvdb/src/lib.rs index a9c74e949..7cacff666 100644 --- a/kvdb/src/lib.rs +++ b/kvdb/src/lib.rs @@ -143,15 +143,19 @@ pub trait KeyValueDB: Sync + Send + parity_util_mem::MallocSizeOf { /// For a given start prefix (inclusive), returns the correct end prefix (non-inclusive). /// This assumes the key bytes are ordered in lexicographical order. -pub fn end_prefix(prefix: &[u8]) -> Vec { +/// Since key length is not limited, for some case we return `None` because there is +/// no bounded limit (every keys in the serie `[]`, `[255]`, `[255, 255]` ...). +pub fn end_prefix(prefix: &[u8]) -> Option> { let mut end_range = prefix.to_vec(); while let Some(0xff) = end_range.last() { end_range.pop(); } if let Some(byte) = end_range.last_mut() { *byte += 1; + Some(end_range) + } else { + None } - end_range } #[cfg(test)] @@ -160,18 +164,18 @@ mod test { #[test] fn end_prefix_test() { - assert_eq!(end_prefix(&[5, 6, 7]), vec![5, 6, 8]); - assert_eq!(end_prefix(&[5, 6, 255]), vec![5, 7]); + assert_eq!(end_prefix(&[5, 6, 7]), Some(vec![5, 6, 8])); + assert_eq!(end_prefix(&[5, 6, 255]), Some(vec![5, 7])); // This is not equal as the result is before start. - assert_ne!(end_prefix(&[5, 255, 255]), vec![5, 255]); + assert_ne!(end_prefix(&[5, 255, 255]), Some(vec![5, 255])); // This is equal ([5, 255] will not be deleted because // it is before start). - assert_eq!(end_prefix(&[5, 255, 255]), vec![6]); - assert_eq!(end_prefix(&[255, 255, 255]), vec![]); + assert_eq!(end_prefix(&[5, 255, 255]), Some(vec![6])); + assert_eq!(end_prefix(&[255, 255, 255]), None); - assert_eq!(end_prefix(&[0x00, 0xff]), vec![0x01]); - assert_eq!(end_prefix(&[0xff]), vec![]); - assert_eq!(end_prefix(b"0"), b"1".to_vec()); - assert_eq!(end_prefix(&[]), vec![]); + assert_eq!(end_prefix(&[0x00, 0xff]), Some(vec![0x01])); + assert_eq!(end_prefix(&[0xff]), None); + assert_eq!(end_prefix(&[]), None); + assert_eq!(end_prefix(b"0"), Some(b"1".to_vec())); } } From 9d1c613863c22c285a25fdb8ed112a128976ef9d Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Mon, 27 Apr 2020 12:18:49 +0200 Subject: [PATCH 52/56] uint: fix UB in uint::from_big_endian (#381) * uint: fix UB in uint::from_fig_endian * uint: add regression tests --- uint/src/uint.rs | 9 ++------- uint/tests/uint_tests.rs | 6 ++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/uint/src/uint.rs b/uint/src/uint.rs index 26b633416..2811d7d6c 100644 --- a/uint/src/uint.rs +++ b/uint/src/uint.rs @@ -1120,13 +1120,8 @@ macro_rules! construct_uint { let mut ret = [0; $n_words]; unsafe { let ret_u8: &mut [u8; $n_words * 8] = $crate::core_::mem::transmute(&mut ret); - let mut ret_ptr = ret_u8.as_mut_ptr(); - let mut slice_ptr = slice.as_ptr().offset(slice.len() as isize - 1); - for _ in 0..slice.len() { - *ret_ptr = *slice_ptr; - ret_ptr = ret_ptr.offset(1); - slice_ptr = slice_ptr.offset(-1); - } + ret_u8[0..slice.len()].copy_from_slice(slice); + ret_u8[0..slice.len()].reverse(); } $name(ret) diff --git a/uint/tests/uint_tests.rs b/uint/tests/uint_tests.rs index 2e226ad36..32a14c728 100644 --- a/uint/tests/uint_tests.rs +++ b/uint/tests/uint_tests.rs @@ -990,6 +990,12 @@ fn from_big_endian() { let number = U256::from_big_endian(&source[..]); assert_eq!(U256::from(1), number); + + let number = U256::from_big_endian(&[]); + assert_eq!(U256::zero(), number); + + let number = U256::from_big_endian(&[1]); + assert_eq!(U256::from(1), number); } #[test] From 89e465eaedad9d3e6ba64732ddcbb71edf504ac6 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Mon, 27 Apr 2020 18:01:37 +0200 Subject: [PATCH 53/56] prepare releases for a few crates (#382) * update changelogs * update versions * update dev-dependency in impl/serde --- ethbloom/CHANGELOG.md | 3 +++ ethbloom/Cargo.toml | 2 +- ethereum-types/CHANGELOG.md | 3 +++ ethereum-types/Cargo.toml | 2 +- fixed-hash/CHANGELOG.md | 3 +++ fixed-hash/Cargo.toml | 2 +- primitive-types/CHANGELOG.md | 3 +++ primitive-types/Cargo.toml | 4 ++-- primitive-types/impls/serde/Cargo.toml | 2 +- uint/CHANGELOG.md | 4 ++++ uint/Cargo.toml | 2 +- 11 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ethbloom/CHANGELOG.md b/ethbloom/CHANGELOG.md index de418cd9d..cc467dae8 100644 --- a/ethbloom/CHANGELOG.md +++ b/ethbloom/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.9.1] - 2020-04-27 +- Added `arbitrary` feature. [#378](https://github.com/paritytech/parity-common/pull/378) + ## [0.9.0] - 2020-03-16 - Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) - License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) diff --git a/ethbloom/Cargo.toml b/ethbloom/Cargo.toml index 1f2de0a62..de61568ce 100644 --- a/ethbloom/Cargo.toml +++ b/ethbloom/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ethbloom" -version = "0.9.0" +version = "0.9.1" authors = ["Parity Technologies "] description = "Ethereum bloom filter" license = "MIT OR Apache-2.0" diff --git a/ethereum-types/CHANGELOG.md b/ethereum-types/CHANGELOG.md index 9455e7bba..c91696835 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.1] - 2020-04-27 +- Added `arbitrary` feature. [#378](https://github.com/paritytech/parity-common/pull/378) + ## [0.9.0] - 2020-03-16 - License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) - Updated dependencies. [#361](https://github.com/paritytech/parity-common/pull/361) diff --git a/ethereum-types/Cargo.toml b/ethereum-types/Cargo.toml index 8d9dc0739..572ad5530 100644 --- a/ethereum-types/Cargo.toml +++ b/ethereum-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ethereum-types" -version = "0.9.0" +version = "0.9.1" authors = ["Parity Technologies "] license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" diff --git a/fixed-hash/CHANGELOG.md b/fixed-hash/CHANGELOG.md index da5ec524d..6db7b6e76 100644 --- a/fixed-hash/CHANGELOG.md +++ b/fixed-hash/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.6.1] - 2020-04-27 +- Added `arbitrary` feature. [#378](https://github.com/paritytech/parity-common/pull/378) + ## [0.6.0] - 2020-03-16 - Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) - License changed from MIT to dual MIT/Apache2. [#342](https://github.com/paritytech/parity-common/pull/342) diff --git a/fixed-hash/Cargo.toml b/fixed-hash/Cargo.toml index 33fd076a0..c8e85585f 100644 --- a/fixed-hash/Cargo.toml +++ b/fixed-hash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fixed-hash" -version = "0.6.0" +version = "0.6.1" authors = ["Parity Technologies "] license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" diff --git a/primitive-types/CHANGELOG.md b/primitive-types/CHANGELOG.md index 4c6f65713..8f5d60af2 100644 --- a/primitive-types/CHANGELOG.md +++ b/primitive-types/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.7.1] - 2020-04-27 +- Added `arbitrary` feature. [#378](https://github.com/paritytech/parity-common/pull/378) + ## [0.7.0] - 2020-03-16 - Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317) diff --git a/primitive-types/Cargo.toml b/primitive-types/Cargo.toml index fcbdc4e63..b64d2b35b 100644 --- a/primitive-types/Cargo.toml +++ b/primitive-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "primitive-types" -version = "0.7.0" +version = "0.7.1" authors = ["Parity Technologies "] license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" @@ -9,7 +9,7 @@ edition = "2018" [dependencies] fixed-hash = { version = "0.6", path = "../fixed-hash", default-features = false } -uint = { version = "0.8.1", path = "../uint", default-features = false } +uint = { version = "0.8.3", path = "../uint", default-features = false } impl-serde = { version = "0.3.0", path = "impls/serde", default-features = false, optional = true } impl-codec = { version = "0.4.1", path = "impls/codec", default-features = false, optional = true } impl-rlp = { version = "0.2", path = "impls/rlp", default-features = false, optional = true } diff --git a/primitive-types/impls/serde/Cargo.toml b/primitive-types/impls/serde/Cargo.toml index ab923bb63..78122b1ff 100644 --- a/primitive-types/impls/serde/Cargo.toml +++ b/primitive-types/impls/serde/Cargo.toml @@ -14,7 +14,7 @@ serde = "1.0.101" criterion = "0.3.0" serde_derive = "1.0.101" serde_json = "1.0.41" -uint = "0.8.1" +uint = { version = "0.8.3", path = "../../../uint" } [[bench]] name = "impl_serde" diff --git a/uint/CHANGELOG.md b/uint/CHANGELOG.md index c04300e84..386475612 100644 --- a/uint/CHANGELOG.md +++ b/uint/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog]. ## [Unreleased] +## [0.8.3] - 2020-04-27 +- Added `arbitrary` feature. [#378](https://github.com/paritytech/parity-common/pull/378) +- Fixed UB in `from_big_endian`. [#381](https://github.com/paritytech/parity-common/pull/381) + ## [0.8.2] - 2019-10-24 ### Fixed - Fixed 2018 edition imports. [#237](https://github.com/paritytech/parity-common/pull/237) diff --git a/uint/Cargo.toml b/uint/Cargo.toml index 97d489884..274b50692 100644 --- a/uint/Cargo.toml +++ b/uint/Cargo.toml @@ -4,7 +4,7 @@ homepage = "http://parity.io" repository = "https://github.com/paritytech/parity-common" license = "MIT OR Apache-2.0" name = "uint" -version = "0.8.2" +version = "0.8.3" authors = ["Parity Technologies "] readme = "README.md" edition = "2018" From 50c3dc2ff733723371678da88d920491879c31cd Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Wed, 29 Apr 2020 19:30:27 +0200 Subject: [PATCH 54/56] kvdb-rocksdb: update rocksdb to 0.14 (#379) * kvdb-rocksdb: update to new set_upper_bound API * kvdb-rocksdb: update rocksdb to crates.io version * kvdb-rocksdb: update the changelog * Fix build? Set VM template. * Fix build? correct image name * Fix build? Maybe it's 2019? * appveyor: try release build * Revert "appveyor: try release build" This reverts commit ace87ee0c81594ff87fb956c79da36a3f382062d. * checkout https://github.com/rust-rocksdb/rust-rocksdb/pull/412 * revert patch * revert unrelated changes Co-authored-by: David Palm --- kvdb-rocksdb/CHANGELOG.md | 1 + kvdb-rocksdb/Cargo.toml | 2 +- kvdb-rocksdb/src/iter.rs | 43 +++++++++++++-------------------------- kvdb-rocksdb/src/lib.rs | 37 ++++++++++++++++----------------- 4 files changed, 34 insertions(+), 49 deletions(-) diff --git a/kvdb-rocksdb/CHANGELOG.md b/kvdb-rocksdb/CHANGELOG.md index cd4838404..c4a46858f 100644 --- a/kvdb-rocksdb/CHANGELOG.md +++ b/kvdb-rocksdb/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- Updated RocksDB to 6.7.3. [#379](https://github.com/paritytech/parity-common/pull/379) ### Breaking - Updated to the new `kvdb` interface. [#313](https://github.com/paritytech/parity-common/pull/313) - Rename and optimize prefix iteration. [#365](https://github.com/paritytech/parity-common/pull/365) diff --git a/kvdb-rocksdb/Cargo.toml b/kvdb-rocksdb/Cargo.toml index 77812b6fe..ee5b2d394 100644 --- a/kvdb-rocksdb/Cargo.toml +++ b/kvdb-rocksdb/Cargo.toml @@ -19,7 +19,7 @@ log = "0.4.8" num_cpus = "1.10.1" parking_lot = "0.10.0" regex = "1.3.1" -rocksdb = { version = "0.13", features = ["snappy"], default-features = false } +rocksdb = { version = "0.14", features = ["snappy"], default-features = false } owning_ref = "0.4.0" parity-util-mem = { path = "../parity-util-mem", version = "0.6", default-features = false, features = ["std", "smallvec"] } diff --git a/kvdb-rocksdb/src/iter.rs b/kvdb-rocksdb/src/iter.rs index 62f9ba9a2..ba8c20e34 100644 --- a/kvdb-rocksdb/src/iter.rs +++ b/kvdb-rocksdb/src/iter.rs @@ -27,13 +27,6 @@ pub type KeyValuePair = (Box<[u8]>, Box<[u8]>); /// Iterator with built-in synchronization. pub struct ReadGuardedIterator<'a, I, T> { inner: OwningHandle>, DerefWrapper>>, - // We store the upper bound here - // to make sure it lives at least as long as the iterator. - // See https://github.com/rust-rocksdb/rust-rocksdb/pull/309. - // TODO: remove this once https://github.com/rust-rocksdb/rust-rocksdb/pull/377 - // is merged and released. - #[allow(dead_code)] - upper_bound_prefix: Option>, } // We can't implement `StableAddress` for a `RwLockReadGuard` @@ -80,15 +73,15 @@ impl<'a, I: Iterator, T> Iterator for ReadGuardedIterator<'a, I, T> { pub trait IterationHandler { type Iterator: Iterator; - /// Create an `Iterator` over a `ColumnFamily` corresponding to the passed index. Takes a - /// reference to a `ReadOptions` to allow configuration of the new iterator (see + /// Create an `Iterator` over a `ColumnFamily` corresponding to the passed index. Takes + /// `ReadOptions` to allow configuration of the new iterator (see /// https://github.com/facebook/rocksdb/blob/master/include/rocksdb/options.h#L1169). - fn iter(&self, col: u32, read_opts: &ReadOptions) -> Self::Iterator; - /// Create an `Iterator` over a `ColumnFamily` corresponding to the passed index. Takes a - /// reference to a `ReadOptions` to allow configuration of the new iterator (see + fn iter(&self, col: u32, read_opts: ReadOptions) -> Self::Iterator; + /// Create an `Iterator` over a `ColumnFamily` corresponding to the passed index. Takes + /// `ReadOptions` to allow configuration of the new iterator (see /// https://github.com/facebook/rocksdb/blob/master/include/rocksdb/options.h#L1169). /// The `Iterator` iterates over keys which start with the provided `prefix`. - fn iter_with_prefix(&self, col: u32, prefix: &[u8], read_opts: &ReadOptions) -> Self::Iterator; + fn iter_with_prefix(&self, col: u32, prefix: &[u8], read_opts: ReadOptions) -> Self::Iterator; } impl<'a, T> ReadGuardedIterator<'a, <&'a T as IterationHandler>::Iterator, T> @@ -97,8 +90,8 @@ where { /// Creates a new `ReadGuardedIterator` that maps `RwLock` to `RwLock`, /// where `DBIterator` iterates over all keys. - pub fn new(read_lock: RwLockReadGuard<'a, Option>, col: u32, read_opts: &ReadOptions) -> Self { - Self { inner: Self::new_inner(read_lock, |db| db.iter(col, read_opts)), upper_bound_prefix: None } + pub fn new(read_lock: RwLockReadGuard<'a, Option>, col: u32, read_opts: ReadOptions) -> Self { + Self { inner: Self::new_inner(read_lock, |db| db.iter(col, read_opts)) } } /// Creates a new `ReadGuardedIterator` that maps `RwLock` to `RwLock`, @@ -107,13 +100,9 @@ where read_lock: RwLockReadGuard<'a, Option>, col: u32, prefix: &[u8], - upper_bound: Option>, - read_opts: &ReadOptions, + read_opts: ReadOptions, ) -> Self { - Self { - inner: Self::new_inner(read_lock, |db| db.iter_with_prefix(col, prefix, read_opts)), - upper_bound_prefix: upper_bound, - } + Self { inner: Self::new_inner(read_lock, |db| db.iter_with_prefix(col, prefix, read_opts)) } } fn new_inner( @@ -130,15 +119,11 @@ where impl<'a> IterationHandler for &'a DBAndColumns { type Iterator = DBIterator<'a>; - fn iter(&self, col: u32, read_opts: &ReadOptions) -> Self::Iterator { - self.db - .iterator_cf_opt(self.cf(col as usize), read_opts, IteratorMode::Start) - .expect("iterator params are valid; qed") + fn iter(&self, col: u32, read_opts: ReadOptions) -> Self::Iterator { + self.db.iterator_cf_opt(self.cf(col as usize), read_opts, IteratorMode::Start) } - fn iter_with_prefix(&self, col: u32, prefix: &[u8], read_opts: &ReadOptions) -> Self::Iterator { - self.db - .iterator_cf_opt(self.cf(col as usize), read_opts, IteratorMode::From(prefix, Direction::Forward)) - .expect("iterator params are valid; qed") + fn iter_with_prefix(&self, col: u32, prefix: &[u8], read_opts: ReadOptions) -> Self::Iterator { + self.db.iterator_cf_opt(self.cf(col as usize), read_opts, IteratorMode::From(prefix, Direction::Forward)) } } diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index d4e76b4c8..4d40b9b2a 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -313,6 +313,12 @@ fn generate_options(config: &DatabaseConfig) -> Options { opts } +fn generate_read_options() -> ReadOptions { + let mut read_opts = ReadOptions::default(); + read_opts.set_verify_checksums(false); + read_opts +} + /// Generate the block based options for RocksDB, based on the given `DatabaseConfig`. fn generate_block_based_options(config: &DatabaseConfig) -> BlockBasedOptions { let mut block_opts = BlockBasedOptions::default(); @@ -360,8 +366,7 @@ impl Database { let column_names: Vec<_> = (0..config.columns).map(|c| format!("col{}", c)).collect(); let write_opts = WriteOptions::default(); - let mut read_opts = ReadOptions::default(); - read_opts.set_verify_checksums(false); + let read_opts = generate_read_options(); let cf_descriptors: Vec<_> = (0..config.columns) .map(|i| ColumnFamilyDescriptor::new(&column_names[i as usize], config.column_config(&block_opts, i))) @@ -436,22 +441,22 @@ impl Database { match op { DBOp::Insert { col: _, key, value } => { stats_total_bytes += key.len() + value.len(); - batch.put_cf(cf, &key, &value).map_err(other_io_err)? + batch.put_cf(cf, &key, &value); } DBOp::Delete { col: _, key } => { // We count deletes as writes. stats_total_bytes += key.len(); - batch.delete_cf(cf, &key).map_err(other_io_err)? + batch.delete_cf(cf, &key); } DBOp::DeletePrefix { col, prefix } => { let end_prefix = kvdb::end_prefix(&prefix[..]); let no_end = end_prefix.is_none(); let end_range = end_prefix.unwrap_or_else(|| vec![u8::max_value(); 16]); - batch.delete_range_cf(cf, &prefix[..], &end_range[..]).map_err(other_io_err)?; + batch.delete_range_cf(cf, &prefix[..], &end_range[..]); if no_end { let prefix = if prefix.len() > end_range.len() { &prefix[..] } else { &end_range[..] }; for (key, _) in self.iter_with_prefix(col, prefix) { - batch.delete_cf(cf, &key[..]).map_err(other_io_err)?; + batch.delete_cf(cf, &key[..]); } } } @@ -502,7 +507,8 @@ impl Database { pub fn iter<'a>(&'a self, col: u32) -> impl Iterator + 'a { let read_lock = self.db.read(); let optional = if read_lock.is_some() { - let guarded = iter::ReadGuardedIterator::new(read_lock, col, &self.read_opts); + let read_opts = generate_read_options(); + let guarded = iter::ReadGuardedIterator::new(read_lock, col, read_opts); Some(guarded) } else { None @@ -516,19 +522,12 @@ impl Database { fn iter_with_prefix<'a>(&'a self, col: u32, prefix: &'a [u8]) -> impl Iterator + 'a { let read_lock = self.db.read(); let optional = if read_lock.is_some() { - let mut read_opts = ReadOptions::default(); - read_opts.set_verify_checksums(false); + let mut read_opts = generate_read_options(); // rocksdb doesn't work with an empty upper bound - let end_prefix = kvdb::end_prefix(prefix).map(|end_prefix| { - let end_prefix = end_prefix.into_boxed_slice(); - // SAFETY: the end_prefix lives as long as the iterator - // See `ReadGuardedIterator` definition for more details. - unsafe { - read_opts.set_iterate_upper_bound(&end_prefix); - } - end_prefix - }); - let guarded = iter::ReadGuardedIterator::new_with_prefix(read_lock, col, prefix, end_prefix, &read_opts); + if let Some(end_prefix) = kvdb::end_prefix(prefix) { + read_opts.set_iterate_upper_bound(end_prefix); + } + let guarded = iter::ReadGuardedIterator::new_with_prefix(read_lock, col, prefix, read_opts); Some(guarded) } else { None From 990d45dd2b5ae40f56640e5fa8c9e012583ea5bd Mon Sep 17 00:00:00 2001 From: Andrew Plaza Date: Fri, 1 May 2020 16:44:39 +0200 Subject: [PATCH 55/56] Add Rocksdb Secondary Instance Api (#384) * kvdb-rocksdb: update to new set_upper_bound API * kvdb-rocksdb: update rocksdb to crates.io version * kvdb-rocksdb: update the changelog * Fix build? Set VM template. * Fix build? correct image name * Fix build? Maybe it's 2019? * appveyor: try release build * Revert "appveyor: try release build" This reverts commit ace87ee0c81594ff87fb956c79da36a3f382062d. * checkout https://github.com/rust-rocksdb/rust-rocksdb/pull/412 * revert patch * revert unrelated changes * add open as secondary rocksdb api * Update kvdb-rocksdb/src/lib.rs Co-Authored-By: Andronik Ordian * add more information to secondary mode comment * add function to catch up a secondary instance with a primary instance * one more doc comment for more clarity * style fixes * Update kvdb-rocksdb/src/lib.rs Co-Authored-By: David * Update kvdb-rocksdb/src/lib.rs Co-Authored-By: David * change name of `secondary_mode` option to `secondary` * Update kvdb-rocksdb/src/lib.rs Co-Authored-By: David * fix some punctuation * specify a different directory for secondary instance to store its logs * Update kvdb-rocksdb/src/lib.rs Co-authored-by: Andronik Ordian * remove catching up on primary db in test * doc comment fixes expand on what `try_catch_up_with_secondary` does, since it may have some implications on the primary instance of rocksdb according to L503-566 in `db/db_impl/db_impl_secondary.cc` of facebook/rocksdb * remove wrong info about blocking primary instance * more docs for catch-up-with-primary * grammar * make `max_open_files` comment clearer Co-authored-by: Andronik Ordian Co-authored-by: David Palm --- kvdb-rocksdb/src/lib.rs | 153 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 138 insertions(+), 15 deletions(-) diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index 4d40b9b2a..2b1fd362a 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -166,6 +166,17 @@ pub struct DatabaseConfig { /// It can have a negative performance impact up to 10% according to /// https://github.com/facebook/rocksdb/wiki/Statistics. pub enable_statistics: bool, + /// Open the database as a secondary instance. + /// Specify a path for the secondary instance of the database. + /// Secondary instances are read-only and kept updated by tailing the rocksdb MANIFEST. + /// It is up to the user to call `catch_up_with_primary()` manually to update the secondary db. + /// Disabled by default. + /// + /// `max_open_files` is overridden to always equal `-1`. + /// May have a negative performance impact on the secondary instance + /// if the secondary instance reads and applies state changes before the primary instance compacts them. + /// More info: https://github.com/facebook/rocksdb/wiki/Secondary-instance + pub secondary: Option, } impl DatabaseConfig { @@ -215,6 +226,7 @@ impl Default for DatabaseConfig { columns: 1, keep_log_file_num: 1, enable_statistics: false, + secondary: None, } } } @@ -305,7 +317,11 @@ fn generate_options(config: &DatabaseConfig) -> Options { } opts.set_use_fsync(false); opts.create_if_missing(true); - opts.set_max_open_files(config.max_open_files); + if config.secondary.is_some() { + opts.set_max_open_files(-1) + } else { + opts.set_max_open_files(config.max_open_files); + } opts.set_bytes_per_sync(1 * MB as u64); opts.set_keep_log_file_num(1); opts.increase_parallelism(cmp::max(1, num_cpus::get() as i32 / 2)); @@ -364,12 +380,38 @@ impl Database { } let column_names: Vec<_> = (0..config.columns).map(|c| format!("col{}", c)).collect(); - let write_opts = WriteOptions::default(); let read_opts = generate_read_options(); + let db = if let Some(secondary_path) = &config.secondary { + Self::open_secondary(&opts, path, secondary_path.as_str(), column_names.as_slice())? + } else { + let column_names: Vec<&str> = column_names.iter().map(|s| s.as_str()).collect(); + Self::open_primary(&opts, path, config, column_names.as_slice(), &block_opts)? + }; + + Ok(Database { + db: RwLock::new(Some(DBAndColumns { db, column_names })), + config: config.clone(), + path: path.to_owned(), + opts, + read_opts, + write_opts, + block_opts, + stats: stats::RunningDbStats::new(), + }) + } + + /// Internal api to open a database in primary mode. + fn open_primary( + opts: &Options, + path: &str, + config: &DatabaseConfig, + column_names: &[&str], + block_opts: &BlockBasedOptions, + ) -> io::Result { let cf_descriptors: Vec<_> = (0..config.columns) - .map(|i| ColumnFamilyDescriptor::new(&column_names[i as usize], config.column_config(&block_opts, i))) + .map(|i| ColumnFamilyDescriptor::new(column_names[i as usize], config.column_config(&block_opts, i))) .collect(); let db = match DB::open_cf_descriptors(&opts, path, cf_descriptors) { @@ -390,7 +432,7 @@ impl Database { ok => ok, }; - let db = match db { + Ok(match db { Ok(db) => db, Err(ref s) if is_corrupted(s) => { warn!("DB corrupted: {}, attempting repair", s); @@ -398,23 +440,34 @@ impl Database { let cf_descriptors: Vec<_> = (0..config.columns) .map(|i| { - ColumnFamilyDescriptor::new(&column_names[i as usize], config.column_config(&block_opts, i)) + ColumnFamilyDescriptor::new(column_names[i as usize], config.column_config(&block_opts, i)) }) .collect(); DB::open_cf_descriptors(&opts, path, cf_descriptors).map_err(other_io_err)? } Err(s) => return Err(other_io_err(s)), - }; - Ok(Database { - db: RwLock::new(Some(DBAndColumns { db, column_names })), - config: config.clone(), - path: path.to_owned(), - opts, - read_opts, - write_opts, - block_opts, - stats: stats::RunningDbStats::new(), + }) + } + + /// Internal api to open a database in secondary mode. + /// Secondary database needs a seperate path to store its own logs. + fn open_secondary( + opts: &Options, + path: &str, + secondary_path: &str, + column_names: &[String], + ) -> io::Result { + let db = DB::open_cf_as_secondary(&opts, path, secondary_path, column_names); + + Ok(match db { + Ok(db) => db, + Err(ref s) if is_corrupted(s) => { + warn!("DB corrupted: {}, attempting repair", s); + DB::repair(&opts, path).map_err(other_io_err)?; + DB::open_cf_as_secondary(&opts, path, secondary_path, column_names).map_err(other_io_err)? + } + Err(s) => return Err(other_io_err(s)), }) } @@ -635,6 +688,33 @@ impl Database { HashMap::new() } } + + /// Try to catch up a secondary instance with + /// the primary by reading as much from the logs as possible. + /// + /// Guaranteed to have changes up to the the time that `try_catch_up_with_primary` is called + /// if it finishes succesfully. + /// + /// Blocks until the MANIFEST file and any state changes in the corresponding Write-Ahead-Logs + /// are applied to the secondary instance. If the manifest files are very large + /// this method could take a long time. + /// + /// If Write-Ahead-Logs have been purged by the primary instance before the secondary + /// is able to open them, the secondary will not be caught up + /// until this function is called again and new Write-Ahead-Logs are identified. + /// + /// If called while the primary is writing, the catch-up may fail. + /// + /// If the secondary is unable to catch up because of missing logs, + /// this method fails silently and no error is returned. + /// + /// Calling this as primary will return an error. + pub fn try_catch_up_with_primary(&self) -> io::Result<()> { + match self.db.read().as_ref() { + Some(DBAndColumns { db, .. }) => db.try_catch_up_with_primary().map_err(other_io_err), + None => Ok(()), + } + } } // duplicate declaration of methods here to avoid trait import in certain existing cases @@ -755,6 +835,48 @@ mod tests { st::test_io_stats(&db) } + #[test] + fn secondary_db_get() -> io::Result<()> { + let primary = TempDir::new("")?; + let config = DatabaseConfig::with_columns(1); + let db = Database::open(&config, primary.path().to_str().expect("tempdir path is valid unicode"))?; + + let key1 = b"key1"; + let mut transaction = db.transaction(); + transaction.put(0, key1, b"horse"); + db.write(transaction)?; + + let config = DatabaseConfig { + secondary: TempDir::new("")?.path().to_str().map(|s| s.to_string()), + ..DatabaseConfig::with_columns(1) + }; + let second_db = Database::open(&config, primary.path().to_str().expect("tempdir path is valid unicode"))?; + assert_eq!(&*second_db.get(0, key1)?.unwrap(), b"horse"); + Ok(()) + } + + #[test] + fn secondary_db_catch_up() -> io::Result<()> { + let primary = TempDir::new("")?; + let config = DatabaseConfig::with_columns(1); + let db = Database::open(&config, primary.path().to_str().expect("tempdir path is valid unicode"))?; + + let config = DatabaseConfig { + secondary: TempDir::new("")?.path().to_str().map(|s| s.to_string()), + ..DatabaseConfig::with_columns(1) + }; + let second_db = Database::open(&config, primary.path().to_str().expect("tempdir path is valid unicode"))?; + + let mut transaction = db.transaction(); + transaction.put(0, b"key1", b"mule"); + transaction.put(0, b"key2", b"cat"); + db.write(transaction)?; + + second_db.try_catch_up_with_primary()?; + assert_eq!(&*second_db.get(0, b"key2")?.unwrap(), b"cat"); + Ok(()) + } + #[test] fn mem_tables_size() { let tempdir = TempDir::new("").unwrap(); @@ -766,6 +888,7 @@ mod tests { columns: 11, keep_log_file_num: 1, enable_statistics: false, + secondary: None, }; let db = Database::open(&config, tempdir.path().to_str().unwrap()).unwrap(); From 371f17fe26cad6dc8f9cce04a779d5a4a21c8319 Mon Sep 17 00:00:00 2001 From: Cheng XU <3105373+xu-cheng@users.noreply.github.com> Date: Sun, 3 May 2020 22:57:45 -0700 Subject: [PATCH 56/56] primitive-types: add no_std support for serde feature (#385) * primitive-types: add no_std support for serde feature This adds no_std support to primitive-types with serde. Due to https://github.com/rust-lang/cargo/issues/3494, a separate new feature `serde_no_std` is created. * primitive-types: update changelog * travis: add tests for primitive-types --- .travis.yml | 2 ++ primitive-types/CHANGELOG.md | 1 + primitive-types/Cargo.toml | 3 ++- primitive-types/impls/serde/Cargo.toml | 6 +++++- primitive-types/impls/serde/src/lib.rs | 8 ++++++++ primitive-types/impls/serde/src/serialize.rs | 8 ++++++-- 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 53e552f6d..a79ed71d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,6 +55,8 @@ script: - cd parity-util-mem/ && cargo test --features=jemalloc-global && cd .. - cd parity-util-mem/ && cargo test --features=mimalloc-global && cd .. - cd parity-util-mem/ && cargo test --no-default-features --features=dlmalloc-global && cd .. + - cd primitive-types/ && cargo test --all-features && cd .. + - cd primitive-types/ && cargo test --no-default-features --features=serde_no_std && cd .. - 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 .. diff --git a/primitive-types/CHANGELOG.md b/primitive-types/CHANGELOG.md index 8f5d60af2..018d16eda 100644 --- a/primitive-types/CHANGELOG.md +++ b/primitive-types/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ ## [Unreleased] +- Added `no_std` support for `serde` feature. [#385](https://github.com/paritytech/parity-common/pull/385) ## [0.7.1] - 2020-04-27 - Added `arbitrary` feature. [#378](https://github.com/paritytech/parity-common/pull/378) diff --git a/primitive-types/Cargo.toml b/primitive-types/Cargo.toml index b64d2b35b..67622a480 100644 --- a/primitive-types/Cargo.toml +++ b/primitive-types/Cargo.toml @@ -19,7 +19,8 @@ default = ["std"] std = ["uint/std", "fixed-hash/std", "impl-codec/std"] byteorder = ["fixed-hash/byteorder"] rustc-hex = ["fixed-hash/rustc-hex"] -serde = ["std", "impl-serde"] +serde = ["std", "impl-serde", "impl-serde/std"] +serde_no_std = ["impl-serde"] codec = ["impl-codec"] rlp = ["impl-rlp"] arbitrary = ["fixed-hash/arbitrary", "uint/arbitrary"] diff --git a/primitive-types/impls/serde/Cargo.toml b/primitive-types/impls/serde/Cargo.toml index 78122b1ff..b89051f75 100644 --- a/primitive-types/impls/serde/Cargo.toml +++ b/primitive-types/impls/serde/Cargo.toml @@ -7,8 +7,12 @@ license = "MIT OR Apache-2.0" homepage = "https://github.com/paritytech/parity-common" description = "Serde serialization support for uint and fixed hash." +[features] +default = ["std"] +std = ["serde/std"] + [dependencies] -serde = "1.0.101" +serde = { version = "1.0.101", default-features = false, features = ["alloc"] } [dev-dependencies] criterion = "0.3.0" diff --git a/primitive-types/impls/serde/src/lib.rs b/primitive-types/impls/serde/src/lib.rs index 500a60cc4..63fe535cb 100644 --- a/primitive-types/impls/serde/src/lib.rs +++ b/primitive-types/impls/serde/src/lib.rs @@ -8,6 +8,14 @@ //! Serde serialization support for uint and fixed hash. +#![no_std] + +#[macro_use] +extern crate alloc; + +#[cfg(feature = "std")] +extern crate std; + #[doc(hidden)] pub use serde; diff --git a/primitive-types/impls/serde/src/serialize.rs b/primitive-types/impls/serde/src/serialize.rs index 542ac0dc8..90e42e2a6 100644 --- a/primitive-types/impls/serde/src/serialize.rs +++ b/primitive-types/impls/serde/src/serialize.rs @@ -6,8 +6,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use alloc::string::String; +use alloc::vec::Vec; +use core::fmt; +use core::result::Result; use serde::{de, Deserializer, Serializer}; -use std::fmt; static CHARS: &[u8] = b"0123456789abcdef"; @@ -58,7 +61,7 @@ fn to_hex_raw<'a>(v: &'a mut [u8], bytes: &[u8], skip_leading_zero: bool) -> &'a } // SAFETY: all characters come either from CHARS or "0x", therefore valid UTF8 - unsafe { std::str::from_utf8_unchecked(&v[0..idx]) } + unsafe { core::str::from_utf8_unchecked(&v[0..idx]) } } /// Decoding bytes from hex string error. @@ -75,6 +78,7 @@ pub enum FromHexError { }, } +#[cfg(feature = "std")] impl std::error::Error for FromHexError {} impl fmt::Display for FromHexError {