spec: ensure types up to date with v0.6.1
This commit is contained in:
parent
9f6b7eb757
commit
3a0f00215d
@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
|||||||
|
|
||||||
/// Details an attestation that can be slashable.
|
/// Details an attestation that can be slashable.
|
||||||
///
|
///
|
||||||
/// Spec v0.6.0
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
Clone,
|
Clone,
|
||||||
|
@ -14,6 +14,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
|||||||
Debug,
|
Debug,
|
||||||
Clone,
|
Clone,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
|
Eq,
|
||||||
Default,
|
Default,
|
||||||
Serialize,
|
Serialize,
|
||||||
Deserialize,
|
Deserialize,
|
||||||
@ -41,8 +42,6 @@ pub struct AttestationData {
|
|||||||
pub crosslink_data_root: Hash256,
|
pub crosslink_data_root: Hash256,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for AttestationData {}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -7,7 +7,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
|||||||
|
|
||||||
/// Two conflicting attestations.
|
/// Two conflicting attestations.
|
||||||
///
|
///
|
||||||
/// Spec v0.6.0
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
|
@ -10,7 +10,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
|||||||
|
|
||||||
/// A block of the `BeaconChain`.
|
/// A block of the `BeaconChain`.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
@ -36,7 +36,7 @@ pub struct BeaconBlock {
|
|||||||
impl BeaconBlock {
|
impl BeaconBlock {
|
||||||
/// Returns an empty block to be used during genesis.
|
/// Returns an empty block to be used during genesis.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
pub fn empty(spec: &ChainSpec) -> BeaconBlock {
|
pub fn empty(spec: &ChainSpec) -> BeaconBlock {
|
||||||
BeaconBlock {
|
BeaconBlock {
|
||||||
slot: spec.genesis_slot,
|
slot: spec.genesis_slot,
|
||||||
@ -49,6 +49,7 @@ impl BeaconBlock {
|
|||||||
block_hash: spec.zero_hash,
|
block_hash: spec.zero_hash,
|
||||||
deposit_count: 0,
|
deposit_count: 0,
|
||||||
},
|
},
|
||||||
|
graffiti: [0; 32],
|
||||||
proposer_slashings: vec![],
|
proposer_slashings: vec![],
|
||||||
attester_slashings: vec![],
|
attester_slashings: vec![],
|
||||||
attestations: vec![],
|
attestations: vec![],
|
||||||
@ -62,7 +63,7 @@ impl BeaconBlock {
|
|||||||
|
|
||||||
/// Returns the `tree_hash_root | update` of the block.
|
/// Returns the `tree_hash_root | update` of the block.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
pub fn canonical_root(&self) -> Hash256 {
|
pub fn canonical_root(&self) -> Hash256 {
|
||||||
Hash256::from_slice(&self.tree_hash_root()[..])
|
Hash256::from_slice(&self.tree_hash_root()[..])
|
||||||
}
|
}
|
||||||
@ -74,7 +75,7 @@ impl BeaconBlock {
|
|||||||
///
|
///
|
||||||
/// Note: performs a full tree-hash of `self.body`.
|
/// Note: performs a full tree-hash of `self.body`.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
pub fn block_header(&self) -> BeaconBlockHeader {
|
pub fn block_header(&self) -> BeaconBlockHeader {
|
||||||
BeaconBlockHeader {
|
BeaconBlockHeader {
|
||||||
slot: self.slot,
|
slot: self.slot,
|
||||||
@ -87,7 +88,7 @@ impl BeaconBlock {
|
|||||||
|
|
||||||
/// Returns a "temporary" header, where the `state_root` is `spec.zero_hash`.
|
/// 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 {
|
pub fn temporary_block_header(&self, spec: &ChainSpec) -> BeaconBlockHeader {
|
||||||
BeaconBlockHeader {
|
BeaconBlockHeader {
|
||||||
state_root: spec.zero_hash,
|
state_root: spec.zero_hash,
|
||||||
|
@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
|||||||
|
|
||||||
/// The body of a `BeaconChain` block, containing operations.
|
/// The body of a `BeaconChain` block, containing operations.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
@ -24,6 +24,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
|||||||
pub struct BeaconBlockBody {
|
pub struct BeaconBlockBody {
|
||||||
pub randao_reveal: Signature,
|
pub randao_reveal: Signature,
|
||||||
pub eth1_data: Eth1Data,
|
pub eth1_data: Eth1Data,
|
||||||
|
pub graffiti: [u8; 32],
|
||||||
pub proposer_slashings: Vec<ProposerSlashing>,
|
pub proposer_slashings: Vec<ProposerSlashing>,
|
||||||
pub attester_slashings: Vec<AttesterSlashing>,
|
pub attester_slashings: Vec<AttesterSlashing>,
|
||||||
pub attestations: Vec<Attestation>,
|
pub attestations: Vec<Attestation>,
|
||||||
|
@ -10,7 +10,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
|||||||
|
|
||||||
/// A header of a `BeaconBlock`.
|
/// A header of a `BeaconBlock`.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
@ -36,14 +36,14 @@ pub struct BeaconBlockHeader {
|
|||||||
impl BeaconBlockHeader {
|
impl BeaconBlockHeader {
|
||||||
/// Returns the `tree_hash_root` of the header.
|
/// Returns the `tree_hash_root` of the header.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
pub fn canonical_root(&self) -> Hash256 {
|
pub fn canonical_root(&self) -> Hash256 {
|
||||||
Hash256::from_slice(&self.signed_root()[..])
|
Hash256::from_slice(&self.signed_root()[..])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a `body`, consumes `self` and returns a complete `BeaconBlock`.
|
/// 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 {
|
pub fn into_block(self, body: BeaconBlockBody) -> BeaconBlock {
|
||||||
BeaconBlock {
|
BeaconBlock {
|
||||||
slot: self.slot,
|
slot: self.slot,
|
||||||
|
@ -55,7 +55,7 @@ pub enum Error {
|
|||||||
|
|
||||||
/// The state of the `BeaconChain` at some slot.
|
/// The state of the `BeaconChain` at some slot.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
PartialEq,
|
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
|
/// 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`.
|
/// deposits. To obtain a full genesis beacon state, use the `BeaconStateBuilder`.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
pub fn genesis(
|
pub fn genesis(
|
||||||
genesis_time: u64,
|
genesis_time: u64,
|
||||||
latest_eth1_data: Eth1Data,
|
latest_eth1_data: Eth1Data,
|
||||||
@ -229,7 +229,7 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
|
|
||||||
/// Returns the `tree_hash_root` of the state.
|
/// Returns the `tree_hash_root` of the state.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
pub fn canonical_root(&self) -> Hash256 {
|
pub fn canonical_root(&self) -> Hash256 {
|
||||||
Hash256::from_slice(&self.tree_hash_root()[..])
|
Hash256::from_slice(&self.tree_hash_root()[..])
|
||||||
}
|
}
|
||||||
@ -258,7 +258,7 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
|
|
||||||
/// The epoch corresponding to `self.slot`.
|
/// The epoch corresponding to `self.slot`.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
pub fn current_epoch(&self, spec: &ChainSpec) -> Epoch {
|
pub fn current_epoch(&self, spec: &ChainSpec) -> Epoch {
|
||||||
self.slot.epoch(spec.slots_per_epoch)
|
self.slot.epoch(spec.slots_per_epoch)
|
||||||
}
|
}
|
||||||
@ -279,7 +279,7 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
|
|
||||||
/// The epoch following `self.current_epoch()`.
|
/// The epoch following `self.current_epoch()`.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
pub fn next_epoch(&self, spec: &ChainSpec) -> Epoch {
|
pub fn next_epoch(&self, spec: &ChainSpec) -> Epoch {
|
||||||
self.current_epoch(spec) + 1
|
self.current_epoch(spec) + 1
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
|||||||
|
|
||||||
/// Specifies the block hash for a shard at an epoch.
|
/// Specifies the block hash for a shard at an epoch.
|
||||||
///
|
///
|
||||||
/// Spec v0.6.0
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
Clone,
|
Clone,
|
||||||
|
@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
|||||||
|
|
||||||
/// A deposit to potentially become a beacon chain validator.
|
/// A deposit to potentially become a beacon chain validator.
|
||||||
///
|
///
|
||||||
/// Spec v0.6.0
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
|
@ -10,7 +10,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
|||||||
|
|
||||||
/// The data supplied by the user to the deposit contract.
|
/// The data supplied by the user to the deposit contract.
|
||||||
///
|
///
|
||||||
/// Spec v0.6.0
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
|
@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
|||||||
|
|
||||||
/// Contains data obtained from the Eth1 chain.
|
/// Contains data obtained from the Eth1 chain.
|
||||||
///
|
///
|
||||||
/// Spec v0.6.0
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
|
@ -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 serde_derive::{Deserialize, Serialize};
|
||||||
use ssz_derive::{Decode, Encode};
|
use ssz_derive::{Decode, Encode};
|
||||||
use test_random_derive::TestRandom;
|
use test_random_derive::TestRandom;
|
||||||
@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
|||||||
///
|
///
|
||||||
/// To be included in an `AttesterSlashing`.
|
/// To be included in an `AttesterSlashing`.
|
||||||
///
|
///
|
||||||
/// Spec v0.6.0
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
@ -28,7 +28,6 @@ pub struct IndexedAttestation {
|
|||||||
pub custody_bit_0_indices: Vec<u64>,
|
pub custody_bit_0_indices: Vec<u64>,
|
||||||
pub custody_bit_1_indices: Vec<u64>,
|
pub custody_bit_1_indices: Vec<u64>,
|
||||||
pub data: AttestationData,
|
pub data: AttestationData,
|
||||||
pub custody_bitfield: Bitfield,
|
|
||||||
#[signed_root(skip_hashing)]
|
#[signed_root(skip_hashing)]
|
||||||
pub signature: AggregateSignature,
|
pub signature: AggregateSignature,
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
|||||||
|
|
||||||
/// Two conflicting proposals from the same proposer (validator).
|
/// Two conflicting proposals from the same proposer (validator).
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
|
@ -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!(4);
|
||||||
|
impl_test_random_for_u8_array!(32);
|
||||||
|
@ -47,7 +47,6 @@ impl TestingAttesterSlashingBuilder {
|
|||||||
custody_bit_0_indices: validator_indices.to_vec(),
|
custody_bit_0_indices: validator_indices.to_vec(),
|
||||||
custody_bit_1_indices: vec![],
|
custody_bit_1_indices: vec![],
|
||||||
data: data_1,
|
data: data_1,
|
||||||
custody_bitfield: Bitfield::new(),
|
|
||||||
signature: AggregateSignature::new(),
|
signature: AggregateSignature::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -55,7 +54,6 @@ impl TestingAttesterSlashingBuilder {
|
|||||||
custody_bit_0_indices: validator_indices.to_vec(),
|
custody_bit_0_indices: validator_indices.to_vec(),
|
||||||
custody_bit_1_indices: vec![],
|
custody_bit_1_indices: vec![],
|
||||||
data: data_2,
|
data: data_2,
|
||||||
custody_bitfield: Bitfield::new(),
|
|
||||||
signature: AggregateSignature::new(),
|
signature: AggregateSignature::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -67,8 +65,7 @@ impl TestingAttesterSlashingBuilder {
|
|||||||
};
|
};
|
||||||
let message = attestation_data_and_custody_bit.tree_hash_root();
|
let message = attestation_data_and_custody_bit.tree_hash_root();
|
||||||
|
|
||||||
for (i, validator_index) in validator_indices.iter().enumerate() {
|
for validator_index in validator_indices {
|
||||||
attestation.custody_bitfield.set(i, false);
|
|
||||||
let signature =
|
let signature =
|
||||||
signer(*validator_index, &message[..], epoch_2, Domain::Attestation);
|
signer(*validator_index, &message[..], epoch_2, Domain::Attestation);
|
||||||
attestation.signature.add(&signature);
|
attestation.signature.add(&signature);
|
||||||
|
@ -11,7 +11,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
|||||||
|
|
||||||
/// The data submitted to the deposit contract.
|
/// The data submitted to the deposit contract.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
Clone,
|
Clone,
|
||||||
|
@ -7,7 +7,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
|||||||
|
|
||||||
/// Information about a `BeaconChain` validator.
|
/// Information about a `BeaconChain` validator.
|
||||||
///
|
///
|
||||||
/// Spec v0.6.0
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
Clone,
|
Clone,
|
||||||
|
@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, SignedRoot, TreeHash};
|
|||||||
|
|
||||||
/// An exit voluntarily submitted a validator who wishes to withdraw.
|
/// An exit voluntarily submitted a validator who wishes to withdraw.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
|
@ -60,7 +60,9 @@ impl CachedTreeHash for bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CachedTreeHash for [u8; 4] {
|
macro_rules! impl_for_u8_array {
|
||||||
|
($len: expr) => {
|
||||||
|
impl CachedTreeHash for [u8; $len] {
|
||||||
fn new_tree_hash_cache(&self, _depth: usize) -> Result<TreeHashCache, Error> {
|
fn new_tree_hash_cache(&self, _depth: usize) -> Result<TreeHashCache, Error> {
|
||||||
Ok(TreeHashCache::from_bytes(
|
Ok(TreeHashCache::from_bytes(
|
||||||
merkleize(self.to_vec()),
|
merkleize(self.to_vec()),
|
||||||
@ -82,6 +84,11 @@ impl CachedTreeHash for [u8; 4] {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_for_u8_array!(4);
|
||||||
|
impl_for_u8_array!(32);
|
||||||
|
|
||||||
impl CachedTreeHash for H256 {
|
impl CachedTreeHash for H256 {
|
||||||
fn new_tree_hash_cache(&self, _depth: usize) -> Result<TreeHashCache, Error> {
|
fn new_tree_hash_cache(&self, _depth: usize) -> Result<TreeHashCache, Error> {
|
||||||
|
@ -57,7 +57,7 @@ impl Decode for bool {
|
|||||||
_ => {
|
_ => {
|
||||||
return Err(DecodeError::BytesInvalid(
|
return Err(DecodeError::BytesInvalid(
|
||||||
format!("Out-of-range for boolean: {}", bytes[0]).to_string(),
|
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!(4);
|
||||||
|
impl_decodable_for_u8_array!(32);
|
||||||
|
|
||||||
impl<T: Decode> Decode for Vec<T> {
|
impl<T: Decode> Decode for Vec<T> {
|
||||||
fn is_ssz_fixed_len() -> bool {
|
fn is_ssz_fixed_len() -> bool {
|
||||||
|
@ -96,6 +96,7 @@ macro_rules! impl_encodable_for_u8_array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl_encodable_for_u8_array!(4);
|
impl_encodable_for_u8_array!(4);
|
||||||
|
impl_encodable_for_u8_array!(32);
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
@ -51,7 +51,9 @@ impl TreeHash for bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TreeHash for [u8; 4] {
|
macro_rules! impl_for_u8_array {
|
||||||
|
($len: expr) => {
|
||||||
|
impl TreeHash for [u8; $len] {
|
||||||
fn tree_hash_type() -> TreeHashType {
|
fn tree_hash_type() -> TreeHashType {
|
||||||
TreeHashType::Vector
|
TreeHashType::Vector
|
||||||
}
|
}
|
||||||
@ -68,6 +70,11 @@ impl TreeHash for [u8; 4] {
|
|||||||
merkle_root(&self[..])
|
merkle_root(&self[..])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_for_u8_array!(4);
|
||||||
|
impl_for_u8_array!(32);
|
||||||
|
|
||||||
impl TreeHash for H256 {
|
impl TreeHash for H256 {
|
||||||
fn tree_hash_type() -> TreeHashType {
|
fn tree_hash_type() -> TreeHashType {
|
||||||
|
Loading…
Reference in New Issue
Block a user