From 77ac49a5536cdd82619c59a4f6f2dbd188a7ccd5 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 15 May 2019 10:40:01 +1000 Subject: [PATCH 1/3] Remove profile.release debug from workspace --- Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a0d375d4..893189941 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,3 @@ members = [ "validator_client", "account_manager", ] - -[profile.release] -debug = true From 4b753015d8d95f3289f21977f356598208390242 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Wed, 15 May 2019 10:40:30 +1000 Subject: [PATCH 2/3] Remove commented-out code --- eth2/utils/fixed_len_vec/src/impls.rs | 3 --- eth2/utils/ssz_derive/src/lib.rs | 6 ------ 2 files changed, 9 deletions(-) diff --git a/eth2/utils/fixed_len_vec/src/impls.rs b/eth2/utils/fixed_len_vec/src/impls.rs index c9d01b9b2..e1c54c1f7 100644 --- a/eth2/utils/fixed_len_vec/src/impls.rs +++ b/eth2/utils/fixed_len_vec/src/impls.rs @@ -1,7 +1,4 @@ use super::*; -// use cached_tree_hash::CachedTreeHash; -// use ssz::{Decode, Encode}; -// use tree_hash::TreeHash; impl tree_hash::TreeHash for FixedLenVec where diff --git a/eth2/utils/ssz_derive/src/lib.rs b/eth2/utils/ssz_derive/src/lib.rs index 25cce2c3c..ef6e2440f 100644 --- a/eth2/utils/ssz_derive/src/lib.rs +++ b/eth2/utils/ssz_derive/src/lib.rs @@ -41,12 +41,6 @@ fn get_serializable_field_types<'a>(struct_data: &'a syn::DataStruct) -> Vec<&'a None } else { Some(&f.ty) - /* - Some(match &f.ident { - Some(ref ident) => ident, - _ => panic!("ssz_derive only supports named struct fields."), - }) - */ } }) .collect() From 3a0f00215d0f2056eab37536967378361044d118 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 15 May 2019 11:48:09 +1000 Subject: [PATCH 3/3] spec: ensure types up to date with v0.6.1 --- eth2/types/src/attestation.rs | 2 +- eth2/types/src/attestation_data.rs | 3 +- eth2/types/src/attester_slashing.rs | 2 +- eth2/types/src/beacon_block.rs | 11 ++--- eth2/types/src/beacon_block_body.rs | 3 +- eth2/types/src/beacon_block_header.rs | 6 +-- eth2/types/src/beacon_state.rs | 10 ++--- eth2/types/src/crosslink.rs | 2 +- eth2/types/src/deposit.rs | 2 +- eth2/types/src/deposit_data.rs | 2 +- eth2/types/src/eth1_data.rs | 2 +- eth2/types/src/indexed_attestation.rs | 5 +-- eth2/types/src/proposer_slashing.rs | 2 +- eth2/types/src/test_utils/test_random.rs | 1 + .../testing_attester_slashing_builder.rs | 5 +-- eth2/types/src/transfer.rs | 2 +- eth2/types/src/validator.rs | 2 +- eth2/types/src/voluntary_exit.rs | 2 +- eth2/utils/cached_tree_hash/src/impls.rs | 41 +++++++++++-------- eth2/utils/ssz/src/decode/impls.rs | 3 +- eth2/utils/ssz/src/encode/impls.rs | 1 + eth2/utils/tree_hash/src/impls.rs | 33 +++++++++------ 22 files changed, 78 insertions(+), 64 deletions(-) diff --git a/eth2/types/src/attestation.rs b/eth2/types/src/attestation.rs index f1fed9d27..682716073 100644 --- a/eth2/types/src/attestation.rs +++ b/eth2/types/src/attestation.rs @@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash}; /// Details an attestation that can be slashable. /// -/// Spec v0.6.0 +/// Spec v0.6.1 #[derive( Debug, Clone, diff --git a/eth2/types/src/attestation_data.rs b/eth2/types/src/attestation_data.rs index 5a7a0dc62..3b0f529d6 100644 --- a/eth2/types/src/attestation_data.rs +++ b/eth2/types/src/attestation_data.rs @@ -14,6 +14,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash}; Debug, Clone, PartialEq, + Eq, Default, Serialize, Deserialize, @@ -41,8 +42,6 @@ pub struct AttestationData { pub crosslink_data_root: Hash256, } -impl Eq for AttestationData {} - #[cfg(test)] mod tests { use super::*; diff --git a/eth2/types/src/attester_slashing.rs b/eth2/types/src/attester_slashing.rs index c3c064503..2b6402fcc 100644 --- a/eth2/types/src/attester_slashing.rs +++ b/eth2/types/src/attester_slashing.rs @@ -7,7 +7,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash}; /// Two conflicting attestations. /// -/// Spec v0.6.0 +/// Spec v0.6.1 #[derive( Debug, PartialEq, diff --git a/eth2/types/src/beacon_block.rs b/eth2/types/src/beacon_block.rs index 3f4dfb0b0..2a829fda2 100644 --- a/eth2/types/src/beacon_block.rs +++ b/eth2/types/src/beacon_block.rs @@ -10,7 +10,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash}; /// A block of the `BeaconChain`. /// -/// Spec v0.5.1 +/// Spec v0.6.1 #[derive( Debug, PartialEq, @@ -36,7 +36,7 @@ pub struct BeaconBlock { impl BeaconBlock { /// Returns an empty block to be used during genesis. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn empty(spec: &ChainSpec) -> BeaconBlock { BeaconBlock { slot: spec.genesis_slot, @@ -49,6 +49,7 @@ impl BeaconBlock { block_hash: spec.zero_hash, deposit_count: 0, }, + graffiti: [0; 32], proposer_slashings: vec![], attester_slashings: vec![], attestations: vec![], @@ -62,7 +63,7 @@ impl BeaconBlock { /// Returns the `tree_hash_root | update` of the block. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn canonical_root(&self) -> Hash256 { Hash256::from_slice(&self.tree_hash_root()[..]) } @@ -74,7 +75,7 @@ impl BeaconBlock { /// /// Note: performs a full tree-hash of `self.body`. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn block_header(&self) -> BeaconBlockHeader { BeaconBlockHeader { slot: self.slot, @@ -87,7 +88,7 @@ impl BeaconBlock { /// Returns a "temporary" header, where the `state_root` is `spec.zero_hash`. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn temporary_block_header(&self, spec: &ChainSpec) -> BeaconBlockHeader { BeaconBlockHeader { state_root: spec.zero_hash, diff --git a/eth2/types/src/beacon_block_body.rs b/eth2/types/src/beacon_block_body.rs index 867db78c4..8bbdbec15 100644 --- a/eth2/types/src/beacon_block_body.rs +++ b/eth2/types/src/beacon_block_body.rs @@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash}; /// The body of a `BeaconChain` block, containing operations. /// -/// Spec v0.5.1 +/// Spec v0.6.1 #[derive( Debug, PartialEq, @@ -24,6 +24,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash}; pub struct BeaconBlockBody { pub randao_reveal: Signature, pub eth1_data: Eth1Data, + pub graffiti: [u8; 32], pub proposer_slashings: Vec, pub attester_slashings: Vec, pub attestations: Vec, diff --git a/eth2/types/src/beacon_block_header.rs b/eth2/types/src/beacon_block_header.rs index 601346db5..f58803c20 100644 --- a/eth2/types/src/beacon_block_header.rs +++ b/eth2/types/src/beacon_block_header.rs @@ -10,7 +10,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash}; /// A header of a `BeaconBlock`. /// -/// Spec v0.5.1 +/// Spec v0.6.1 #[derive( Debug, PartialEq, @@ -36,14 +36,14 @@ pub struct BeaconBlockHeader { impl BeaconBlockHeader { /// Returns the `tree_hash_root` of the header. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn canonical_root(&self) -> Hash256 { Hash256::from_slice(&self.signed_root()[..]) } /// Given a `body`, consumes `self` and returns a complete `BeaconBlock`. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn into_block(self, body: BeaconBlockBody) -> BeaconBlock { BeaconBlock { slot: self.slot, diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index fd8821bd8..4c6f8d2a2 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -55,7 +55,7 @@ pub enum Error { /// The state of the `BeaconChain` at some slot. /// -/// Spec v0.5.1 +/// Spec v0.6.1 #[derive( Debug, PartialEq, @@ -150,7 +150,7 @@ impl BeaconState { /// This does not fully build a genesis beacon state, it omits processing of initial validator /// deposits. To obtain a full genesis beacon state, use the `BeaconStateBuilder`. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn genesis( genesis_time: u64, latest_eth1_data: Eth1Data, @@ -229,7 +229,7 @@ impl BeaconState { /// Returns the `tree_hash_root` of the state. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn canonical_root(&self) -> Hash256 { Hash256::from_slice(&self.tree_hash_root()[..]) } @@ -258,7 +258,7 @@ impl BeaconState { /// The epoch corresponding to `self.slot`. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn current_epoch(&self, spec: &ChainSpec) -> Epoch { self.slot.epoch(spec.slots_per_epoch) } @@ -279,7 +279,7 @@ impl BeaconState { /// The epoch following `self.current_epoch()`. /// - /// Spec v0.5.1 + /// Spec v0.6.1 pub fn next_epoch(&self, spec: &ChainSpec) -> Epoch { self.current_epoch(spec) + 1 } diff --git a/eth2/types/src/crosslink.rs b/eth2/types/src/crosslink.rs index f44d1166e..9a06ca8bf 100644 --- a/eth2/types/src/crosslink.rs +++ b/eth2/types/src/crosslink.rs @@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash}; /// Specifies the block hash for a shard at an epoch. /// -/// Spec v0.6.0 +/// Spec v0.6.1 #[derive( Debug, Clone, diff --git a/eth2/types/src/deposit.rs b/eth2/types/src/deposit.rs index 34fab4699..1b031b0d5 100644 --- a/eth2/types/src/deposit.rs +++ b/eth2/types/src/deposit.rs @@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash}; /// A deposit to potentially become a beacon chain validator. /// -/// Spec v0.6.0 +/// Spec v0.6.1 #[derive( Debug, PartialEq, diff --git a/eth2/types/src/deposit_data.rs b/eth2/types/src/deposit_data.rs index e1f6d1b1d..d00bb69e2 100644 --- a/eth2/types/src/deposit_data.rs +++ b/eth2/types/src/deposit_data.rs @@ -10,7 +10,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash}; /// The data supplied by the user to the deposit contract. /// -/// Spec v0.6.0 +/// Spec v0.6.1 #[derive( Debug, PartialEq, diff --git a/eth2/types/src/eth1_data.rs b/eth2/types/src/eth1_data.rs index 97f37e415..0a7043543 100644 --- a/eth2/types/src/eth1_data.rs +++ b/eth2/types/src/eth1_data.rs @@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash}; /// Contains data obtained from the Eth1 chain. /// -/// Spec v0.6.0 +/// Spec v0.6.1 #[derive( Debug, PartialEq, diff --git a/eth2/types/src/indexed_attestation.rs b/eth2/types/src/indexed_attestation.rs index af294dfc1..14f6e470b 100644 --- a/eth2/types/src/indexed_attestation.rs +++ b/eth2/types/src/indexed_attestation.rs @@ -1,4 +1,4 @@ -use crate::{test_utils::TestRandom, AggregateSignature, AttestationData, Bitfield}; +use crate::{test_utils::TestRandom, AggregateSignature, AttestationData}; use serde_derive::{Deserialize, Serialize}; use ssz_derive::{Decode, Encode}; use test_random_derive::TestRandom; @@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash}; /// /// To be included in an `AttesterSlashing`. /// -/// Spec v0.6.0 +/// Spec v0.6.1 #[derive( Debug, PartialEq, @@ -28,7 +28,6 @@ pub struct IndexedAttestation { pub custody_bit_0_indices: Vec, pub custody_bit_1_indices: Vec, pub data: AttestationData, - pub custody_bitfield: Bitfield, #[signed_root(skip_hashing)] pub signature: AggregateSignature, } diff --git a/eth2/types/src/proposer_slashing.rs b/eth2/types/src/proposer_slashing.rs index 0c419dd56..b4d5ef0e5 100644 --- a/eth2/types/src/proposer_slashing.rs +++ b/eth2/types/src/proposer_slashing.rs @@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash}; /// Two conflicting proposals from the same proposer (validator). /// -/// Spec v0.5.1 +/// Spec v0.6.1 #[derive( Debug, PartialEq, diff --git a/eth2/types/src/test_utils/test_random.rs b/eth2/types/src/test_utils/test_random.rs index ceb785424..4f56d1596 100644 --- a/eth2/types/src/test_utils/test_random.rs +++ b/eth2/types/src/test_utils/test_random.rs @@ -81,3 +81,4 @@ macro_rules! impl_test_random_for_u8_array { } impl_test_random_for_u8_array!(4); +impl_test_random_for_u8_array!(32); diff --git a/eth2/types/src/test_utils/testing_attester_slashing_builder.rs b/eth2/types/src/test_utils/testing_attester_slashing_builder.rs index 9a8c145de..6cde3f145 100644 --- a/eth2/types/src/test_utils/testing_attester_slashing_builder.rs +++ b/eth2/types/src/test_utils/testing_attester_slashing_builder.rs @@ -47,7 +47,6 @@ impl TestingAttesterSlashingBuilder { custody_bit_0_indices: validator_indices.to_vec(), custody_bit_1_indices: vec![], data: data_1, - custody_bitfield: Bitfield::new(), signature: AggregateSignature::new(), }; @@ -55,7 +54,6 @@ impl TestingAttesterSlashingBuilder { custody_bit_0_indices: validator_indices.to_vec(), custody_bit_1_indices: vec![], data: data_2, - custody_bitfield: Bitfield::new(), signature: AggregateSignature::new(), }; @@ -67,8 +65,7 @@ impl TestingAttesterSlashingBuilder { }; let message = attestation_data_and_custody_bit.tree_hash_root(); - for (i, validator_index) in validator_indices.iter().enumerate() { - attestation.custody_bitfield.set(i, false); + for validator_index in validator_indices { let signature = signer(*validator_index, &message[..], epoch_2, Domain::Attestation); attestation.signature.add(&signature); diff --git a/eth2/types/src/transfer.rs b/eth2/types/src/transfer.rs index 176a9d75d..ffac85c7b 100644 --- a/eth2/types/src/transfer.rs +++ b/eth2/types/src/transfer.rs @@ -11,7 +11,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash}; /// The data submitted to the deposit contract. /// -/// Spec v0.5.1 +/// Spec v0.6.1 #[derive( Debug, Clone, diff --git a/eth2/types/src/validator.rs b/eth2/types/src/validator.rs index 437112c04..ad65a8c60 100644 --- a/eth2/types/src/validator.rs +++ b/eth2/types/src/validator.rs @@ -7,7 +7,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash}; /// Information about a `BeaconChain` validator. /// -/// Spec v0.6.0 +/// Spec v0.6.1 #[derive( Debug, Clone, diff --git a/eth2/types/src/voluntary_exit.rs b/eth2/types/src/voluntary_exit.rs index a138fb480..6754aa2c9 100644 --- a/eth2/types/src/voluntary_exit.rs +++ b/eth2/types/src/voluntary_exit.rs @@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash}; /// An exit voluntarily submitted a validator who wishes to withdraw. /// -/// Spec v0.5.1 +/// Spec v0.6.1 #[derive( Debug, PartialEq, diff --git a/eth2/utils/cached_tree_hash/src/impls.rs b/eth2/utils/cached_tree_hash/src/impls.rs index 5105ad6a7..aec61f34b 100644 --- a/eth2/utils/cached_tree_hash/src/impls.rs +++ b/eth2/utils/cached_tree_hash/src/impls.rs @@ -60,29 +60,36 @@ impl CachedTreeHash for bool { } } -impl CachedTreeHash for [u8; 4] { - fn new_tree_hash_cache(&self, _depth: usize) -> Result { - Ok(TreeHashCache::from_bytes( - merkleize(self.to_vec()), - false, - None, - )?) - } +macro_rules! impl_for_u8_array { + ($len: expr) => { + impl CachedTreeHash for [u8; $len] { + fn new_tree_hash_cache(&self, _depth: usize) -> Result { + Ok(TreeHashCache::from_bytes( + merkleize(self.to_vec()), + false, + None, + )?) + } - fn tree_hash_cache_schema(&self, depth: usize) -> BTreeSchema { - BTreeSchema::from_lengths(depth, vec![1]) - } + fn tree_hash_cache_schema(&self, depth: usize) -> BTreeSchema { + BTreeSchema::from_lengths(depth, vec![1]) + } - fn update_tree_hash_cache(&self, cache: &mut TreeHashCache) -> Result<(), Error> { - let leaf = merkleize(self.to_vec()); - cache.maybe_update_chunk(cache.chunk_index, &leaf)?; + fn update_tree_hash_cache(&self, cache: &mut TreeHashCache) -> Result<(), Error> { + let leaf = merkleize(self.to_vec()); + cache.maybe_update_chunk(cache.chunk_index, &leaf)?; - cache.chunk_index += 1; + cache.chunk_index += 1; - Ok(()) - } + Ok(()) + } + } + }; } +impl_for_u8_array!(4); +impl_for_u8_array!(32); + impl CachedTreeHash for H256 { fn new_tree_hash_cache(&self, _depth: usize) -> Result { Ok(TreeHashCache::from_bytes( diff --git a/eth2/utils/ssz/src/decode/impls.rs b/eth2/utils/ssz/src/decode/impls.rs index 8a5a36780..cecc1935e 100644 --- a/eth2/utils/ssz/src/decode/impls.rs +++ b/eth2/utils/ssz/src/decode/impls.rs @@ -57,7 +57,7 @@ impl Decode for bool { _ => { return Err(DecodeError::BytesInvalid( format!("Out-of-range for boolean: {}", bytes[0]).to_string(), - )) + )); } } } @@ -114,6 +114,7 @@ macro_rules! impl_decodable_for_u8_array { } impl_decodable_for_u8_array!(4); +impl_decodable_for_u8_array!(32); impl Decode for Vec { fn is_ssz_fixed_len() -> bool { diff --git a/eth2/utils/ssz/src/encode/impls.rs b/eth2/utils/ssz/src/encode/impls.rs index 07886d68f..dbe4e700a 100644 --- a/eth2/utils/ssz/src/encode/impls.rs +++ b/eth2/utils/ssz/src/encode/impls.rs @@ -96,6 +96,7 @@ macro_rules! impl_encodable_for_u8_array { } impl_encodable_for_u8_array!(4); +impl_encodable_for_u8_array!(32); #[cfg(test)] mod tests { diff --git a/eth2/utils/tree_hash/src/impls.rs b/eth2/utils/tree_hash/src/impls.rs index 42ea9add0..212aba3c8 100644 --- a/eth2/utils/tree_hash/src/impls.rs +++ b/eth2/utils/tree_hash/src/impls.rs @@ -51,24 +51,31 @@ impl TreeHash for bool { } } -impl TreeHash for [u8; 4] { - fn tree_hash_type() -> TreeHashType { - TreeHashType::Vector - } +macro_rules! impl_for_u8_array { + ($len: expr) => { + impl TreeHash for [u8; $len] { + fn tree_hash_type() -> TreeHashType { + TreeHashType::Vector + } - fn tree_hash_packed_encoding(&self) -> Vec { - unreachable!("bytesN should never be packed.") - } + fn tree_hash_packed_encoding(&self) -> Vec { + unreachable!("bytesN should never be packed.") + } - fn tree_hash_packing_factor() -> usize { - unreachable!("bytesN should never be packed.") - } + fn tree_hash_packing_factor() -> usize { + unreachable!("bytesN should never be packed.") + } - fn tree_hash_root(&self) -> Vec { - merkle_root(&self[..]) - } + fn tree_hash_root(&self) -> Vec { + merkle_root(&self[..]) + } + } + }; } +impl_for_u8_array!(4); +impl_for_u8_array!(32); + impl TreeHash for H256 { fn tree_hash_type() -> TreeHashType { TreeHashType::Vector