Merge branch '368' into ef-tests

This commit is contained in:
Paul Hauner 2019-05-15 12:33:40 +10:00
commit 519ee81c68
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
25 changed files with 78 additions and 76 deletions

View File

@ -34,6 +34,3 @@ members = [
"validator_client",
"account_manager",
]
[profile.release]
debug = true

View File

@ -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,

View File

@ -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::*;

View File

@ -7,7 +7,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
/// Two conflicting attestations.
///
/// Spec v0.6.0
/// Spec v0.6.1
#[derive(
Debug,
PartialEq,

View File

@ -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,

View File

@ -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<ProposerSlashing>,
pub attester_slashings: Vec<AttesterSlashing>,
pub attestations: Vec<Attestation>,

View File

@ -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,

View File

@ -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<T: EthSpec> BeaconState<T> {
/// 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<T: EthSpec> BeaconState<T> {
/// 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<T: EthSpec> BeaconState<T> {
/// 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<T: EthSpec> BeaconState<T> {
/// 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
}

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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<u64>,
pub custody_bit_1_indices: Vec<u64>,
pub data: AttestationData,
pub custody_bitfield: Bitfield,
#[signed_root(skip_hashing)]
pub signature: AggregateSignature,
}

View File

@ -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,

View File

@ -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);

View File

@ -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);

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -60,29 +60,36 @@ impl CachedTreeHash for bool {
}
}
impl CachedTreeHash for [u8; 4] {
fn new_tree_hash_cache(&self, _depth: usize) -> Result<TreeHashCache, Error> {
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<TreeHashCache, Error> {
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<TreeHashCache, Error> {
Ok(TreeHashCache::from_bytes(

View File

@ -1,7 +1,4 @@
use super::*;
// use cached_tree_hash::CachedTreeHash;
// use ssz::{Decode, Encode};
// use tree_hash::TreeHash;
impl<T, N: Unsigned> tree_hash::TreeHash for FixedLenVec<T, N>
where

View File

@ -57,7 +57,7 @@ impl Decode for bool {
_ => {
return Err(DecodeError::BytesInvalid(
format!("Out-of-range for boolean: {}", bytes[0]).to_string(),
))
));
}
}
}
@ -156,6 +156,7 @@ macro_rules! impl_decodable_for_u8_array {
}
impl_decodable_for_u8_array!(4);
impl_decodable_for_u8_array!(32);
impl<T: Decode> Decode for Vec<T> {
fn is_ssz_fixed_len() -> bool {

View File

@ -132,6 +132,7 @@ macro_rules! impl_encodable_for_u8_array {
}
impl_encodable_for_u8_array!(4);
impl_encodable_for_u8_array!(32);
#[cfg(test)]
mod tests {

View File

@ -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()

View File

@ -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<u8> {
unreachable!("bytesN should never be packed.")
}
fn tree_hash_packed_encoding(&self) -> Vec<u8> {
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<u8> {
merkle_root(&self[..])
}
fn tree_hash_root(&self) -> Vec<u8> {
merkle_root(&self[..])
}
}
};
}
impl_for_u8_array!(4);
impl_for_u8_array!(32);
impl TreeHash for H256 {
fn tree_hash_type() -> TreeHashType {
TreeHashType::Vector