Add new tree_hash crate project wide.

This commit is contained in:
Paul Hauner 2019-04-16 14:25:43 +10:00
parent b8c4c3308a
commit f69b56ad60
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
13 changed files with 18 additions and 17 deletions

View File

@ -23,4 +23,5 @@ serde_json = "1.0"
slot_clock = { path = "../../eth2/utils/slot_clock" } slot_clock = { path = "../../eth2/utils/slot_clock" }
ssz = { path = "../../eth2/utils/ssz" } ssz = { path = "../../eth2/utils/ssz" }
state_processing = { path = "../../eth2/state_processing" } state_processing = { path = "../../eth2/state_processing" }
tree_hash = { path = "../../eth2/utils/tree_hash" }
types = { path = "../../eth2/types" } types = { path = "../../eth2/types" }

View File

@ -38,5 +38,6 @@ serde_json = "1.0"
serde_yaml = "0.8" serde_yaml = "0.8"
slot_clock = { path = "../../../eth2/utils/slot_clock" } slot_clock = { path = "../../../eth2/utils/slot_clock" }
ssz = { path = "../../../eth2/utils/ssz" } ssz = { path = "../../../eth2/utils/ssz" }
tree_hash = { path = "../../../eth2/utils/tree_hash" }
types = { path = "../../../eth2/types" } types = { path = "../../../eth2/types" }
yaml-rust = "0.4.2" yaml-rust = "0.4.2"

View File

@ -15,6 +15,7 @@ version = { path = "../version" }
types = { path = "../../eth2/types" } types = { path = "../../eth2/types" }
slog = { version = "^2.2.3" , features = ["max_level_trace", "release_max_level_debug"] } slog = { version = "^2.2.3" , features = ["max_level_trace", "release_max_level_debug"] }
ssz = { path = "../../eth2/utils/ssz" } ssz = { path = "../../eth2/utils/ssz" }
tree_hash = { path = "../../eth2/utils/tree_hash" }
futures = "0.1.25" futures = "0.1.25"
error-chain = "0.12.0" error-chain = "0.12.0"
crossbeam-channel = "0.3.8" crossbeam-channel = "0.3.8"

View File

@ -7,4 +7,5 @@ edition = "2018"
[dependencies] [dependencies]
slot_clock = { path = "../../eth2/utils/slot_clock" } slot_clock = { path = "../../eth2/utils/slot_clock" }
ssz = { path = "../../eth2/utils/ssz" } ssz = { path = "../../eth2/utils/ssz" }
tree_hash = { path = "../../eth2/utils/tree_hash" }
types = { path = "../../eth2/types" } types = { path = "../../eth2/types" }

View File

@ -141,8 +141,7 @@ impl<T: SlotClock, U: BeaconNode, V: DutiesReader, W: Signer> Attester<T, U, V,
data: attestation_data.clone(), data: attestation_data.clone(),
custody_bit: PHASE_0_CUSTODY_BIT, custody_bit: PHASE_0_CUSTODY_BIT,
} }
.tree_hash_root .tree_hash_root();
| update();
self.signer self.signer
.sign_attestation_message(&message[..], DOMAIN_ATTESTATION) .sign_attestation_message(&message[..], DOMAIN_ATTESTATION)

View File

@ -8,4 +8,5 @@ edition = "2018"
int_to_bytes = { path = "../utils/int_to_bytes" } int_to_bytes = { path = "../utils/int_to_bytes" }
slot_clock = { path = "../utils/slot_clock" } slot_clock = { path = "../utils/slot_clock" }
ssz = { path = "../utils/ssz" } ssz = { path = "../utils/ssz" }
tree_hash = { path = "../../eth2/utils/tree_hash" }
types = { path = "../types" } types = { path = "../types" }

View File

@ -2,8 +2,8 @@ pub mod test_utils;
mod traits; mod traits;
use slot_clock::SlotClock; use slot_clock::SlotClock;
use ssz::{SignedRoot, TreeHash};
use std::sync::Arc; use std::sync::Arc;
use tree_hash::{SignedRoot, TreeHash};
use types::{BeaconBlock, ChainSpec, Domain, Slot}; use types::{BeaconBlock, ChainSpec, Domain, Slot};
pub use self::traits::{ pub use self::traits::{

View File

@ -26,5 +26,7 @@ log = "0.4"
merkle_proof = { path = "../utils/merkle_proof" } merkle_proof = { path = "../utils/merkle_proof" }
ssz = { path = "../utils/ssz" } ssz = { path = "../utils/ssz" }
ssz_derive = { path = "../utils/ssz_derive" } ssz_derive = { path = "../utils/ssz_derive" }
tree_hash = { path = "../utils/tree_hash" }
tree_hash_derive = { path = "../utils/tree_hash_derive" }
types = { path = "../types" } types = { path = "../types" }
rayon = "1.0" rayon = "1.0"

View File

@ -1,7 +1,7 @@
use crate::common::slash_validator; use crate::common::slash_validator;
use errors::{BlockInvalid as Invalid, BlockProcessingError as Error, IntoWithIndex}; use errors::{BlockInvalid as Invalid, BlockProcessingError as Error, IntoWithIndex};
use rayon::prelude::*; use rayon::prelude::*;
use ssz::{SignedRoot, TreeHash}; use tree_hash::{SignedRoot, TreeHash};
use types::*; use types::*;
pub use self::verify_attester_slashing::{ pub use self::verify_attester_slashing::{

View File

@ -5,7 +5,8 @@ use bls_aggregates::{
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use serde_hex::{encode as hex_encode, HexVisitor}; use serde_hex::{encode as hex_encode, HexVisitor};
use ssz::{decode, hash, Decodable, DecodeError, Encodable, SszStream, TreeHash}; use ssz::{decode, Decodable, DecodeError, Encodable, SszStream};
use tree_hash::impl_tree_hash_for_ssz_bytes;
/// A BLS aggregate signature. /// A BLS aggregate signature.
/// ///
@ -165,11 +166,7 @@ impl<'de> Deserialize<'de> for AggregateSignature {
} }
} }
impl TreeHash for AggregateSignature { impl_tree_hash_for_ssz_bytes!(AggregateSignature);
fn tree_hash_root(&self) -> Vec<u8> {
hash(&self.as_bytes())
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View File

@ -4,7 +4,8 @@ use hex::encode as hex_encode;
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use serde_hex::HexVisitor; 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. /// A single BLS signature.
/// ///
@ -114,11 +115,7 @@ impl Decodable for Signature {
} }
} }
impl TreeHash for Signature { impl_tree_hash_for_ssz_bytes!(Signature);
fn tree_hash_root(&self) -> Vec<u8> {
hash(&self.as_bytes())
}
}
impl Serialize for Signature { impl Serialize for Signature {
/// Serde serialization is compliant the Ethereum YAML test format. /// Serde serialization is compliant the Ethereum YAML test format.

View File

@ -17,6 +17,7 @@ block_proposer = { path = "../eth2/block_proposer" }
attester = { path = "../eth2/attester" } attester = { path = "../eth2/attester" }
bls = { path = "../eth2/utils/bls" } bls = { path = "../eth2/utils/bls" }
ssz = { path = "../eth2/utils/ssz" } ssz = { path = "../eth2/utils/ssz" }
tree_hash = { path = "../eth2/utils/tree_hash" }
clap = "2.32.0" clap = "2.32.0"
dirs = "1.0.3" dirs = "1.0.3"
grpcio = { version = "0.4", default-features = false, features = ["protobuf-codec"] } grpcio = { version = "0.4", default-features = false, features = ["protobuf-codec"] }

View File

@ -6,8 +6,8 @@ pub use self::beacon_node_block::{BeaconNodeError, PublishOutcome};
pub use self::grpc::BeaconBlockGrpcClient; pub use self::grpc::BeaconBlockGrpcClient;
use crate::signer::Signer; use crate::signer::Signer;
use slog::{error, info, warn}; use slog::{error, info, warn};
use ssz::{SignedRoot, TreeHash};
use std::sync::Arc; use std::sync::Arc;
use tree_hash::{SignedRoot, TreeHash};
use types::{BeaconBlock, ChainSpec, Domain, Fork, Slot}; use types::{BeaconBlock, ChainSpec, Domain, Fork, Slot};
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]