Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
69 changes: 33 additions & 36 deletions ethbloom/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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);
//! ```
//!

Expand Down
26 changes: 8 additions & 18 deletions fixed-hash/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<H256>(), 32);
/// # }
/// assert_eq!(std::mem::size_of::<H256>(), 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::<H160>(), 20);
/// # }
/// assert_eq!(std::mem::size_of::<H160>(), 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::<H512>(), 64);
/// # }
/// assert_eq!(std::mem::size_of::<H512>(), 64);
/// ```
#[macro_export(local_inner_macros)]
macro_rules! construct_fixed_hash {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions fixed-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ pub use rand;
#[doc(hidden)]
pub use quickcheck;

#[cfg(test)]
extern crate rand_xorshift;

#[macro_use]
mod hash;

Expand Down
1 change: 1 addition & 0 deletions keccak-hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
45 changes: 22 additions & 23 deletions keccak-hash/benches/keccak_256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,36 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

#![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) {
pub fn keccak_256_with_typical_input(c: &mut Criterion) {
let data: Vec<u8> = From::from("some medum length string with important information");
Comment thread
ordian marked this conversation as resolved.
Outdated
b.bytes = data.len() as u64;
b.iter(|| {
let _out = keccak(&data);
})
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<u8> = From::from("IGxcKBr1Qp7tuqtpSVhAbvt7UgWLEi7mCA6Wa185seLSIJLFS8K1aAFO9AwtO9b3n9SM3Qg136JMmy9Mj9gZ84IaUm8XioPtloabFDU5ZR1wvauJT6jNTkvBVBpUigIsyU7C1u3s99vKP64LpXqvo1hwItZKtISxmUAgzzjv5q14V4G9bkKAnmc4M5xixgLsDGZmnj6HcOMY3XRkWtxN3RscSKwPA0bfpgtz27ZVHplbXwloYRgRLpjRhZJc7sqO8RFnTHKasVkxVRcUoDBvWNJK27T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oFfHrhqHXNz5A0uWMgxUS50c60zLl6QAELxHaCGba4WCMOHIo5nSKcUuYtDyDoDlrezALW5mZR4PRPRxnjrXxbJI14qrpymRReC3QgFDJp6sT5TLwvSHaavPlEbt2Eu0Kh5SXklGHXP9YuF3glGuJzSob3NakW1RXF5786U1MHhtJby64LyGWvNn4QXie3VjeL3QQu4C9crEAxSSiOJOfnL3DYIVOY4ipUkKFlF7Rp2q6gZazDvcUCp1cbcr7T7B4s22rXzjN7mHYWOyWuZGwlImeorY3aVKi7BaXbhgOFw6BUmIc1HeGFELHIEnPE9MwOjZam3LOm0rhBHlvJJZkXvJKmDUJrGlyqC5GtC5lDWLfXewyDWDqq7PY0atVQily5GWqib6wub6u6LZ3HZDNP8gK64Nf4kC259AE4V2hCohDnSsXAIoOkehwXyp6CkDT42NJb6sXHUv2N6cm292MiKA22PKWrwUGsan599KI2V67YRDfcfiB4ZHRDiSe62MBE0fGLIgXLIWw1xTWYbPQ9YAj3xovBvmewbJ1De4k6uS");
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));
})
});
}
1 change: 1 addition & 0 deletions kvdb-rocksdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I broke this in https://github.com/paritytech/parity-common/pull/301/files#diff-3206254ae7bfdf4d978075eb4cafbdcfR30, but we didn't have CI checks to catch it because keccak-hash benches didn't compile on stable I think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this is a bench-only dependency)

kvdb-shared-tests = { path = "../kvdb-shared-tests", version = "0.1" }
rand = "0.7.2"
tempdir = "0.3.7"
5 changes: 1 addition & 4 deletions parity-crypto/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

#[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,);

Expand Down
10 changes: 5 additions & 5 deletions primitive-types/impls/serde/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub enum FromHexError {
impl std::error::Error for FromHexError {}

impl fmt::Display for FromHexError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
Comment thread
ordian marked this conversation as resolved.
Outdated
match *self {
Self::MissingPrefix => write!(fmt, "0x prefix is missing"),
Self::InvalidHex { character, index } => write!(fmt, "invalid hex character: {}, at {}", character, index),
Expand Down Expand Up @@ -186,7 +186,7 @@ pub enum ExpectedLen<'a> {
}

impl<'a> fmt::Display for ExpectedLen<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
ExpectedLen::Exact(ref v) => write!(fmt, "length of {}", v.len() * 2),
ExpectedLen::Between(min, ref v) => write!(fmt, "length between ({}; {}]", min * 2, v.len() * 2),
Expand All @@ -205,7 +205,7 @@ where
impl<'b> de::Visitor<'b> for Visitor {
type Value = Vec<u8>;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "a 0x-prefixed hex string")
}

Expand Down Expand Up @@ -234,7 +234,7 @@ where
impl<'a, 'b> de::Visitor<'b> for Visitor<'a> {
type Value = usize;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "a 0x-prefixed hex string with {}", self.len)
}

Expand Down Expand Up @@ -272,7 +272,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
extern crate serde_derive;
use serde_derive;

use self::serde_derive::{Deserialize, Serialize};

Expand Down
24 changes: 8 additions & 16 deletions rlp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(bytes: &[u8]) -> Result<T, DecoderError>
where
Expand All @@ -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<E>(object: &E) -> Vec<u8>
where
Expand Down
Loading