Update various v0.5.1 tags, delete old file
This commit is contained in:
parent
9790968378
commit
fabb42a162
@ -1,29 +1,30 @@
|
|||||||
use super::AttestationData;
|
use super::AttestationData;
|
||||||
use crate::test_utils::TestRandom;
|
use crate::test_utils::TestRandom;
|
||||||
|
|
||||||
use rand::RngCore;
|
|
||||||
use serde_derive::Serialize;
|
use serde_derive::Serialize;
|
||||||
use ssz_derive::{Decode, Encode};
|
use ssz_derive::{Decode, Encode};
|
||||||
|
use test_random_derive::TestRandom;
|
||||||
use tree_hash_derive::{CachedTreeHash, TreeHash};
|
use tree_hash_derive::{CachedTreeHash, TreeHash};
|
||||||
|
|
||||||
/// Used for pairing an attestation with a proof-of-custody.
|
/// Used for pairing an attestation with a proof-of-custody.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
#[derive(Debug, Clone, PartialEq, Default, Serialize, Encode, Decode, TreeHash, CachedTreeHash)]
|
#[derive(
|
||||||
|
Debug,
|
||||||
|
Clone,
|
||||||
|
PartialEq,
|
||||||
|
Default,
|
||||||
|
Serialize,
|
||||||
|
Encode,
|
||||||
|
Decode,
|
||||||
|
TreeHash,
|
||||||
|
CachedTreeHash,
|
||||||
|
TestRandom,
|
||||||
|
)]
|
||||||
pub struct AttestationDataAndCustodyBit {
|
pub struct AttestationDataAndCustodyBit {
|
||||||
pub data: AttestationData,
|
pub data: AttestationData,
|
||||||
pub custody_bit: bool,
|
pub custody_bit: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestRandom for AttestationDataAndCustodyBit {
|
|
||||||
fn random_for_test(rng: &mut impl RngCore) -> Self {
|
|
||||||
Self {
|
|
||||||
data: <_>::random_for_test(rng),
|
|
||||||
custody_bit: <_>::random_for_test(rng),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -56,35 +56,35 @@ pub trait EthSpec:
|
|||||||
|
|
||||||
/// Returns the `SHARD_COUNT` constant for this specification.
|
/// Returns the `SHARD_COUNT` constant for this specification.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
fn shard_count() -> usize {
|
fn shard_count() -> usize {
|
||||||
Self::ShardCount::to_usize()
|
Self::ShardCount::to_usize()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `SLOTS_PER_HISTORICAL_ROOT` constant for this specification.
|
/// Returns the `SLOTS_PER_HISTORICAL_ROOT` constant for this specification.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
fn slots_per_historical_root() -> usize {
|
fn slots_per_historical_root() -> usize {
|
||||||
Self::SlotsPerHistoricalRoot::to_usize()
|
Self::SlotsPerHistoricalRoot::to_usize()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `LATEST_RANDAO_MIXES_LENGTH` constant for this specification.
|
/// Returns the `LATEST_RANDAO_MIXES_LENGTH` constant for this specification.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
fn latest_randao_mixes_length() -> usize {
|
fn latest_randao_mixes_length() -> usize {
|
||||||
Self::LatestRandaoMixesLength::to_usize()
|
Self::LatestRandaoMixesLength::to_usize()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `LATEST_ACTIVE_INDEX_ROOTS` constant for this specification.
|
/// Returns the `LATEST_ACTIVE_INDEX_ROOTS` constant for this specification.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
fn latest_active_index_roots() -> usize {
|
fn latest_active_index_roots() -> usize {
|
||||||
Self::LatestActiveIndexRootsLength::to_usize()
|
Self::LatestActiveIndexRootsLength::to_usize()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the `LATEST_SLASHED_EXIT_LENGTH` constant for this specification.
|
/// Returns the `LATEST_SLASHED_EXIT_LENGTH` constant for this specification.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
fn latest_slashed_exit_length() -> usize {
|
fn latest_slashed_exit_length() -> usize {
|
||||||
Self::LatestSlashedExitLength::to_usize()
|
Self::LatestSlashedExitLength::to_usize()
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ pub trait EthSpec:
|
|||||||
|
|
||||||
/// Ethereum Foundation specifications.
|
/// Ethereum Foundation specifications.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct FoundationEthSpec;
|
pub struct FoundationEthSpec;
|
||||||
|
|
||||||
@ -111,8 +111,6 @@ impl EthSpec for FoundationEthSpec {
|
|||||||
pub type FoundationBeaconState = BeaconState<FoundationEthSpec>;
|
pub type FoundationBeaconState = BeaconState<FoundationEthSpec>;
|
||||||
|
|
||||||
/// Ethereum Foundation specifications, modified to be suitable for < 1000 validators.
|
/// Ethereum Foundation specifications, modified to be suitable for < 1000 validators.
|
||||||
///
|
|
||||||
/// Spec v0.5.1
|
|
||||||
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct FewValidatorsEthSpec;
|
pub struct FewValidatorsEthSpec;
|
||||||
|
|
||||||
@ -131,8 +129,6 @@ impl EthSpec for FewValidatorsEthSpec {
|
|||||||
pub type FewValidatorsBeaconState = BeaconState<FewValidatorsEthSpec>;
|
pub type FewValidatorsBeaconState = BeaconState<FewValidatorsEthSpec>;
|
||||||
|
|
||||||
/// Specifications suitable for a small-scale (< 1000 validators) lighthouse testnet.
|
/// Specifications suitable for a small-scale (< 1000 validators) lighthouse testnet.
|
||||||
///
|
|
||||||
/// Spec v0.5.1
|
|
||||||
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct LighthouseTestnetEthSpec;
|
pub struct LighthouseTestnetEthSpec;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ pub struct DepositData {
|
|||||||
impl DepositData {
|
impl DepositData {
|
||||||
/// Generate the signature for a given DepositData details.
|
/// Generate the signature for a given DepositData details.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
pub fn create_signature(
|
pub fn create_signature(
|
||||||
&self,
|
&self,
|
||||||
secret_key: &SecretKey,
|
secret_key: &SecretKey,
|
||||||
@ -48,16 +48,6 @@ impl DepositData {
|
|||||||
|
|
||||||
Signature::new(msg.as_slice(), domain, secret_key)
|
Signature::new(msg.as_slice(), domain, secret_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify that proof-of-possession is valid.
|
|
||||||
///
|
|
||||||
/// Spec v0.5.1
|
|
||||||
pub fn validate_signature(&self, epoch: Epoch, fork: &Fork, spec: &ChainSpec) -> bool {
|
|
||||||
let msg = self.signed_root();
|
|
||||||
let domain = spec.get_domain(epoch, Domain::Deposit, fork);
|
|
||||||
|
|
||||||
self.signature.verify(&msg, domain, &self.pubkey)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -66,23 +56,4 @@ mod tests {
|
|||||||
|
|
||||||
ssz_tests!(DepositData);
|
ssz_tests!(DepositData);
|
||||||
cached_tree_hash_tests!(DepositData);
|
cached_tree_hash_tests!(DepositData);
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn can_create_and_validate() {
|
|
||||||
let spec = ChainSpec::foundation();
|
|
||||||
let fork = Fork::genesis(&spec);
|
|
||||||
let keypair = Keypair::random();
|
|
||||||
let epoch = Epoch::new(0);
|
|
||||||
|
|
||||||
let mut deposit_input = DepositData {
|
|
||||||
pubkey: keypair.pk.clone(),
|
|
||||||
amount: 0,
|
|
||||||
withdrawal_credentials: Hash256::zero(),
|
|
||||||
signature: Signature::empty_signature(),
|
|
||||||
};
|
|
||||||
|
|
||||||
deposit_input.signature = deposit_input.create_signature(&keypair.sk, epoch, &fork, &spec);
|
|
||||||
|
|
||||||
assert!(deposit_input.validate_signature(epoch, &fork, &spec));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
use super::Eth1Data;
|
|
||||||
use crate::test_utils::TestRandom;
|
|
||||||
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
|
||||||
use ssz_derive::{Decode, Encode};
|
|
||||||
use test_random_derive::TestRandom;
|
|
||||||
use tree_hash_derive::{CachedTreeHash, TreeHash};
|
|
||||||
|
|
||||||
/// A summation of votes for some `Eth1Data`.
|
|
||||||
///
|
|
||||||
/// Spec v0.5.1
|
|
||||||
#[derive(
|
|
||||||
Debug,
|
|
||||||
PartialEq,
|
|
||||||
Clone,
|
|
||||||
Default,
|
|
||||||
Serialize,
|
|
||||||
Deserialize,
|
|
||||||
Encode,
|
|
||||||
Decode,
|
|
||||||
TreeHash,
|
|
||||||
CachedTreeHash,
|
|
||||||
TestRandom,
|
|
||||||
)]
|
|
||||||
pub struct Eth1DataVote {
|
|
||||||
pub eth1_data: Eth1Data,
|
|
||||||
pub vote_count: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
ssz_tests!(Eth1DataVote);
|
|
||||||
cached_tree_hash_tests!(Eth1DataVote);
|
|
||||||
}
|
|
@ -9,7 +9,7 @@ use tree_hash_derive::{CachedTreeHash, TreeHash};
|
|||||||
|
|
||||||
/// Historical block and state roots.
|
/// Historical block and state roots.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
Clone,
|
Clone,
|
||||||
|
@ -9,7 +9,7 @@ pub enum Error {
|
|||||||
/// Defines the epochs relative to some epoch. Most useful when referring to the committees prior
|
/// Defines the epochs relative to some epoch. Most useful when referring to the committees prior
|
||||||
/// to and following some epoch.
|
/// to and following some epoch.
|
||||||
///
|
///
|
||||||
/// Spec v0.5.1
|
/// Spec v0.6.1
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
pub enum RelativeEpoch {
|
pub enum RelativeEpoch {
|
||||||
/// The prior epoch.
|
/// The prior epoch.
|
||||||
|
Loading…
Reference in New Issue
Block a user