From f69b56ad6032d906b79aa086e55ee9097ca685df Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 16 Apr 2019 14:25:43 +1000 Subject: [PATCH] Add new `tree_hash` crate project wide. --- beacon_node/beacon_chain/Cargo.toml | 1 + beacon_node/beacon_chain/test_harness/Cargo.toml | 1 + beacon_node/network/Cargo.toml | 1 + eth2/attester/Cargo.toml | 1 + eth2/attester/src/lib.rs | 3 +-- eth2/block_proposer/Cargo.toml | 1 + eth2/block_proposer/src/lib.rs | 2 +- eth2/state_processing/Cargo.toml | 2 ++ eth2/state_processing/src/per_block_processing.rs | 2 +- eth2/utils/bls/src/aggregate_signature.rs | 9 +++------ eth2/utils/bls/src/signature.rs | 9 +++------ validator_client/Cargo.toml | 1 + validator_client/src/block_producer/mod.rs | 2 +- 13 files changed, 18 insertions(+), 17 deletions(-) diff --git a/beacon_node/beacon_chain/Cargo.toml b/beacon_node/beacon_chain/Cargo.toml index 55d4bacfd..e2a4527a9 100644 --- a/beacon_node/beacon_chain/Cargo.toml +++ b/beacon_node/beacon_chain/Cargo.toml @@ -23,4 +23,5 @@ serde_json = "1.0" slot_clock = { path = "../../eth2/utils/slot_clock" } ssz = { path = "../../eth2/utils/ssz" } state_processing = { path = "../../eth2/state_processing" } +tree_hash = { path = "../../eth2/utils/tree_hash" } types = { path = "../../eth2/types" } diff --git a/beacon_node/beacon_chain/test_harness/Cargo.toml b/beacon_node/beacon_chain/test_harness/Cargo.toml index 50d154732..a2abf6c5a 100644 --- a/beacon_node/beacon_chain/test_harness/Cargo.toml +++ b/beacon_node/beacon_chain/test_harness/Cargo.toml @@ -38,5 +38,6 @@ serde_json = "1.0" serde_yaml = "0.8" slot_clock = { path = "../../../eth2/utils/slot_clock" } ssz = { path = "../../../eth2/utils/ssz" } +tree_hash = { path = "../../../eth2/utils/tree_hash" } types = { path = "../../../eth2/types" } yaml-rust = "0.4.2" diff --git a/beacon_node/network/Cargo.toml b/beacon_node/network/Cargo.toml index cd2c2269a..36bf1f141 100644 --- a/beacon_node/network/Cargo.toml +++ b/beacon_node/network/Cargo.toml @@ -15,6 +15,7 @@ version = { path = "../version" } types = { path = "../../eth2/types" } slog = { version = "^2.2.3" , features = ["max_level_trace", "release_max_level_debug"] } ssz = { path = "../../eth2/utils/ssz" } +tree_hash = { path = "../../eth2/utils/tree_hash" } futures = "0.1.25" error-chain = "0.12.0" crossbeam-channel = "0.3.8" diff --git a/eth2/attester/Cargo.toml b/eth2/attester/Cargo.toml index 956ecf565..41824274d 100644 --- a/eth2/attester/Cargo.toml +++ b/eth2/attester/Cargo.toml @@ -7,4 +7,5 @@ edition = "2018" [dependencies] slot_clock = { path = "../../eth2/utils/slot_clock" } ssz = { path = "../../eth2/utils/ssz" } +tree_hash = { path = "../../eth2/utils/tree_hash" } types = { path = "../../eth2/types" } diff --git a/eth2/attester/src/lib.rs b/eth2/attester/src/lib.rs index a9e3091af..1bbbd6b43 100644 --- a/eth2/attester/src/lib.rs +++ b/eth2/attester/src/lib.rs @@ -141,8 +141,7 @@ impl Attester Deserialize<'de> for AggregateSignature { } } -impl TreeHash for AggregateSignature { - fn tree_hash_root(&self) -> Vec { - hash(&self.as_bytes()) - } -} +impl_tree_hash_for_ssz_bytes!(AggregateSignature); #[cfg(test)] mod tests { diff --git a/eth2/utils/bls/src/signature.rs b/eth2/utils/bls/src/signature.rs index 30b55a787..cf6c8fe5a 100644 --- a/eth2/utils/bls/src/signature.rs +++ b/eth2/utils/bls/src/signature.rs @@ -4,7 +4,8 @@ use hex::encode as hex_encode; use serde::de::{Deserialize, Deserializer}; use serde::ser::{Serialize, Serializer}; use serde_hex::HexVisitor; -use ssz::{decode, hash, ssz_encode, Decodable, DecodeError, Encodable, SszStream, TreeHash}; +use ssz::{decode, ssz_encode, Decodable, DecodeError, Encodable, SszStream}; +use tree_hash::impl_tree_hash_for_ssz_bytes; /// A single BLS signature. /// @@ -114,11 +115,7 @@ impl Decodable for Signature { } } -impl TreeHash for Signature { - fn tree_hash_root(&self) -> Vec { - hash(&self.as_bytes()) - } -} +impl_tree_hash_for_ssz_bytes!(Signature); impl Serialize for Signature { /// Serde serialization is compliant the Ethereum YAML test format. diff --git a/validator_client/Cargo.toml b/validator_client/Cargo.toml index 80477c8ea..7f6b0cee9 100644 --- a/validator_client/Cargo.toml +++ b/validator_client/Cargo.toml @@ -17,6 +17,7 @@ block_proposer = { path = "../eth2/block_proposer" } attester = { path = "../eth2/attester" } bls = { path = "../eth2/utils/bls" } ssz = { path = "../eth2/utils/ssz" } +tree_hash = { path = "../eth2/utils/tree_hash" } clap = "2.32.0" dirs = "1.0.3" grpcio = { version = "0.4", default-features = false, features = ["protobuf-codec"] } diff --git a/validator_client/src/block_producer/mod.rs b/validator_client/src/block_producer/mod.rs index 9cc0460c7..2689b302d 100644 --- a/validator_client/src/block_producer/mod.rs +++ b/validator_client/src/block_producer/mod.rs @@ -6,8 +6,8 @@ pub use self::beacon_node_block::{BeaconNodeError, PublishOutcome}; pub use self::grpc::BeaconBlockGrpcClient; use crate::signer::Signer; use slog::{error, info, warn}; -use ssz::{SignedRoot, TreeHash}; use std::sync::Arc; +use tree_hash::{SignedRoot, TreeHash}; use types::{BeaconBlock, ChainSpec, Domain, Fork, Slot}; #[derive(Debug, PartialEq)]