From 25b08f009640b7e223d8947a925f836dadaea50f Mon Sep 17 00:00:00 2001 From: Kirk Baird Date: Mon, 11 Mar 2019 15:22:15 +1100 Subject: [PATCH] Run cargo fmt --- .../test_harness/src/beacon_chain_harness.rs | 16 ++++--- .../beacon_chain_harness/generate_deposits.rs | 46 ++++++++++--------- .../test_harness/src/test_case.rs | 8 +++- beacon_node/src/main.rs | 6 +-- eth2/types/src/beacon_state.rs | 9 +--- eth2/types/src/deposit_input.rs | 21 +++++++-- .../src/test_utils/testing_deposit_builder.rs | 17 +++---- eth2/utils/bls/src/lib.rs | 1 - 8 files changed, 73 insertions(+), 51 deletions(-) diff --git a/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs b/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs index ea32e177d..7a84456b8 100644 --- a/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs +++ b/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs @@ -118,12 +118,16 @@ impl BeaconChainHarness { let deposits = generate_deposits_from_keypairs( &keypairs, genesis_time, - spec.get_domain(spec.genesis_epoch, Domain::Deposit, &Fork{ - previous_version: spec.genesis_fork_version, - current_version: spec.genesis_fork_version, - epoch: spec.genesis_epoch, - }), - &spec + spec.get_domain( + spec.genesis_epoch, + Domain::Deposit, + &Fork { + previous_version: spec.genesis_fork_version, + current_version: spec.genesis_fork_version, + epoch: spec.genesis_epoch, + }, + ), + &spec, ); state_builder.process_initial_deposits(&deposits, &spec); }; diff --git a/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness/generate_deposits.rs b/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness/generate_deposits.rs index 2baf8984f..f568f03e5 100644 --- a/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness/generate_deposits.rs +++ b/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness/generate_deposits.rs @@ -42,28 +42,32 @@ pub fn generate_deposits_from_keypairs( keypairs.len() ); - let initial_validator_deposits = - keypairs - .par_iter() - .map(|keypair| { - let withdrawal_credentials = Hash256::from_slice( - &get_withdrawal_credentials(&keypair.pk, spec.bls_withdrawal_prefix_byte)[..]); - Deposit { - branch: vec![], // branch verification is not specified. - index: 0, // index verification is not specified. - deposit_data: DepositData { - amount: 32_000_000_000, // 32 ETH (in Gwei) - timestamp: genesis_time - 1, - deposit_input: DepositInput { - pubkey: keypair.pk.clone(), - // Validator can withdraw using their main keypair. - withdrawal_credentials: withdrawal_credentials.clone(), - proof_of_possession: DepositInput::create_proof_of_possession(&keypair, &withdrawal_credentials, domain), - }, + let initial_validator_deposits = keypairs + .par_iter() + .map(|keypair| { + let withdrawal_credentials = Hash256::from_slice( + &get_withdrawal_credentials(&keypair.pk, spec.bls_withdrawal_prefix_byte)[..], + ); + Deposit { + branch: vec![], // branch verification is not specified. + index: 0, // index verification is not specified. + deposit_data: DepositData { + amount: 32_000_000_000, // 32 ETH (in Gwei) + timestamp: genesis_time - 1, + deposit_input: DepositInput { + pubkey: keypair.pk.clone(), + // Validator can withdraw using their main keypair. + withdrawal_credentials: withdrawal_credentials.clone(), + proof_of_possession: DepositInput::create_proof_of_possession( + &keypair, + &withdrawal_credentials, + domain, + ), }, - } - }) - .collect(); + }, + } + }) + .collect(); initial_validator_deposits } diff --git a/beacon_node/beacon_chain/test_harness/src/test_case.rs b/beacon_node/beacon_chain/test_harness/src/test_case.rs index 32a16ff80..a18b4688b 100644 --- a/beacon_node/beacon_chain/test_harness/src/test_case.rs +++ b/beacon_node/beacon_chain/test_harness/src/test_case.rs @@ -265,10 +265,14 @@ fn build_deposit( &keypair, &withdrawal_credentials, harness.spec.get_domain( - harness.beacon_chain.state.read().current_epoch(&harness.spec), + harness + .beacon_chain + .state + .read() + .current_epoch(&harness.spec), Domain::Deposit, &harness.beacon_chain.state.read().fork, - ) + ), ); let index = harness.beacon_chain.state.read().deposit_index + index_offset; diff --git a/beacon_node/src/main.rs b/beacon_node/src/main.rs index 8fdfa3446..c3182c789 100644 --- a/beacon_node/src/main.rs +++ b/beacon_node/src/main.rs @@ -19,8 +19,8 @@ use slot_clock::SystemTimeSlotClock; use ssz::TreeHash; use std::sync::Arc; use types::{ - beacon_state::BeaconStateBuilder, BeaconBlock, ChainSpec, Domain, Deposit, DepositData, DepositInput, - Eth1Data, Fork, Hash256, Keypair, + beacon_state::BeaconStateBuilder, BeaconBlock, ChainSpec, Deposit, DepositData, DepositInput, + Domain, Eth1Data, Fork, Hash256, Keypair, }; fn main() { @@ -123,7 +123,7 @@ fn main() { previous_version: spec.genesis_fork_version, current_version: spec.genesis_fork_version, epoch: spec.genesis_epoch, - } + }, ), ), }, diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index f98b3e47e..f69746dae 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -618,19 +618,14 @@ impl BeaconState { pubkey_map: Option<&HashMap>, spec: &ChainSpec, ) -> Result { - let proof_is_valid = deposit_input.proof_of_possession.verify( &deposit_input.signed_root(), - spec.get_domain( - self.current_epoch(&spec), - Domain::Deposit, - &self.fork, - ), + spec.get_domain(self.current_epoch(&spec), Domain::Deposit, &self.fork), &deposit_input.pubkey, ); if !proof_is_valid { - return Err(()) + return Err(()); } let pubkey = deposit_input.pubkey.clone(); diff --git a/eth2/types/src/deposit_input.rs b/eth2/types/src/deposit_input.rs index bb2334672..2a61efd9c 100644 --- a/eth2/types/src/deposit_input.rs +++ b/eth2/types/src/deposit_input.rs @@ -3,14 +3,25 @@ use crate::test_utils::TestRandom; use bls::{Keypair, PublicKey, Signature}; use rand::RngCore; use serde_derive::{Deserialize, Serialize}; -use ssz_derive::{Decode, Encode, SignedRoot, TreeHash}; use ssz::{SignedRoot, TreeHash}; +use ssz_derive::{Decode, Encode, SignedRoot, TreeHash}; use test_random_derive::TestRandom; /// The data supplied by the user to the deposit contract. /// /// Spec v0.4.0 -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, SignedRoot, TreeHash, TestRandom)] +#[derive( + Debug, + PartialEq, + Clone, + Serialize, + Deserialize, + Encode, + Decode, + SignedRoot, + TreeHash, + TestRandom, +)] pub struct DepositInput { pub pubkey: PublicKey, pub withdrawal_credentials: Hash256, @@ -21,7 +32,11 @@ impl DepositInput { /// Generate the 'proof_of_posession' signature for a given DepositInput details. /// /// Spec v0.4.0 - pub fn create_proof_of_possession(keypair: &Keypair, withdrawal_credentials: &Hash256, domain: u64) -> Signature { + pub fn create_proof_of_possession( + keypair: &Keypair, + withdrawal_credentials: &Hash256, + domain: u64, + ) -> Signature { let signable_deposite_input = DepositInput { pubkey: keypair.pk.clone(), withdrawal_credentials: withdrawal_credentials.clone(), diff --git a/eth2/types/src/test_utils/testing_deposit_builder.rs b/eth2/types/src/test_utils/testing_deposit_builder.rs index 4e754eab0..80e039a89 100644 --- a/eth2/types/src/test_utils/testing_deposit_builder.rs +++ b/eth2/types/src/test_utils/testing_deposit_builder.rs @@ -1,5 +1,5 @@ use crate::*; -use bls::{get_withdrawal_credentials}; +use bls::get_withdrawal_credentials; pub struct TestingDepositBuilder { deposit: Deposit, @@ -31,15 +31,16 @@ impl TestingDepositBuilder { } pub fn sign(&mut self, keypair: &Keypair, domain: u64, spec: &ChainSpec) { - let withdrawal_credentials = Hash256::from_slice(&get_withdrawal_credentials(&keypair.pk, spec.bls_withdrawal_prefix_byte)[..]); + let withdrawal_credentials = Hash256::from_slice( + &get_withdrawal_credentials(&keypair.pk, spec.bls_withdrawal_prefix_byte)[..], + ); self.deposit.deposit_data.deposit_input.pubkey = keypair.pk.clone(); - self.deposit.deposit_data.deposit_input.withdrawal_credentials = withdrawal_credentials.clone(); + self.deposit + .deposit_data + .deposit_input + .withdrawal_credentials = withdrawal_credentials.clone(); self.deposit.deposit_data.deposit_input.proof_of_possession = - DepositInput::create_proof_of_possession( - &keypair, - &withdrawal_credentials, - domain, - ); + DepositInput::create_proof_of_possession(&keypair, &withdrawal_credentials, domain); } pub fn build(self) -> Deposit { diff --git a/eth2/utils/bls/src/lib.rs b/eth2/utils/bls/src/lib.rs index 4888ff567..b995b78c9 100644 --- a/eth2/utils/bls/src/lib.rs +++ b/eth2/utils/bls/src/lib.rs @@ -29,7 +29,6 @@ pub fn verify_proof_of_possession(sig: &Signature, pubkey: &PublicKey) -> bool { sig.verify(&ssz_encode(pubkey), 0, &pubkey) } - /// Returns the withdrawal credentials for a given public key. pub fn get_withdrawal_credentials(pubkey: &PublicKey, prefix_byte: u8) -> Vec { let hashed = hash(&ssz_encode(pubkey));