mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 13:28:33 +00:00
Merge new beacon block, Rust 2018
This commit is contained in:
@@ -68,7 +68,7 @@ impl ValidatorInductor {
|
||||
randao_commitment: r.randao_commitment,
|
||||
randao_last_change: self.current_slot,
|
||||
balance: DEPOSIT_GWEI,
|
||||
status: status as u8,
|
||||
status: status,
|
||||
exit_slot: 0,
|
||||
})
|
||||
}
|
||||
@@ -77,7 +77,7 @@ impl ValidatorInductor {
|
||||
/// `validator.status == Withdrawn`. If no such record exists, `None` is returned.
|
||||
fn first_withdrawn_validator(&mut self) -> Option<usize> {
|
||||
for i in self.empty_validator_start..self.validators.len() {
|
||||
if self.validators[i].status == ValidatorStatus::Withdrawn as u8 {
|
||||
if self.validators[i].status == ValidatorStatus::Withdrawn {
|
||||
self.empty_validator_start = i + 1;
|
||||
return Some(i);
|
||||
}
|
||||
@@ -110,8 +110,8 @@ impl ValidatorInductor {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use bls::{Keypair, Signature};
|
||||
use hashing::proof_of_possession_hash;
|
||||
use bls::{create_proof_of_possession, Keypair, Signature};
|
||||
use hashing::canonical_hash;
|
||||
use types::{Address, Hash256};
|
||||
|
||||
fn registration_equals_record(reg: &ValidatorRegistration, rec: &ValidatorRecord) -> bool {
|
||||
@@ -122,12 +122,6 @@ mod tests {
|
||||
& (verify_proof_of_possession(®.proof_of_possession, &rec.pubkey))
|
||||
}
|
||||
|
||||
/// Generate a proof of possession for some keypair.
|
||||
fn get_proof_of_possession(kp: &Keypair) -> Signature {
|
||||
let pop_message = proof_of_possession_hash(&kp.pk.as_bytes());
|
||||
Signature::new_hashed(&pop_message, &kp.sk)
|
||||
}
|
||||
|
||||
/// Generate a basic working ValidatorRegistration for use in tests.
|
||||
fn get_registration() -> ValidatorRegistration {
|
||||
let kp = Keypair::random();
|
||||
@@ -136,7 +130,7 @@ mod tests {
|
||||
withdrawal_shard: 0,
|
||||
withdrawal_address: Address::zero(),
|
||||
randao_commitment: Hash256::zero(),
|
||||
proof_of_possession: get_proof_of_possession(&kp),
|
||||
proof_of_possession: create_proof_of_possession(&kp),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,8 +160,8 @@ mod tests {
|
||||
let _ = inductor.induct(&r, ValidatorStatus::Active);
|
||||
let validators = inductor.to_vec();
|
||||
|
||||
assert!(validators[0].status == ValidatorStatus::PendingActivation as u8);
|
||||
assert!(validators[1].status == ValidatorStatus::Active as u8);
|
||||
assert!(validators[0].status == ValidatorStatus::PendingActivation);
|
||||
assert!(validators[1].status == ValidatorStatus::Active);
|
||||
assert_eq!(validators.len(), 2);
|
||||
}
|
||||
|
||||
@@ -176,7 +170,7 @@ mod tests {
|
||||
let mut validators = vec![];
|
||||
for _ in 0..5 {
|
||||
let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair();
|
||||
v.status = ValidatorStatus::Active as u8;
|
||||
v.status = ValidatorStatus::Active;
|
||||
validators.push(v);
|
||||
}
|
||||
|
||||
@@ -195,11 +189,11 @@ mod tests {
|
||||
fn test_validator_inductor_valid_all_second_validator_withdrawn() {
|
||||
let mut validators = vec![];
|
||||
let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair();
|
||||
v.status = ValidatorStatus::Active as u8;
|
||||
v.status = ValidatorStatus::Active;
|
||||
validators.push(v);
|
||||
for _ in 0..4 {
|
||||
let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair();
|
||||
v.status = ValidatorStatus::Withdrawn as u8;
|
||||
v.status = ValidatorStatus::Withdrawn;
|
||||
validators.push(v);
|
||||
}
|
||||
|
||||
@@ -219,7 +213,7 @@ mod tests {
|
||||
let mut validators = vec![];
|
||||
for _ in 0..5 {
|
||||
let (mut v, _) = ValidatorRecord::zero_with_thread_rand_keypair();
|
||||
v.status = ValidatorStatus::Withdrawn as u8;
|
||||
v.status = ValidatorStatus::Withdrawn;
|
||||
validators.push(v);
|
||||
}
|
||||
|
||||
@@ -266,7 +260,7 @@ mod tests {
|
||||
|
||||
let mut r = get_registration();
|
||||
let kp = Keypair::random();
|
||||
r.proof_of_possession = get_proof_of_possession(&kp);
|
||||
r.proof_of_possession = create_proof_of_possession(&kp);
|
||||
|
||||
let mut inductor = ValidatorInductor::new(0, 1024, validators);
|
||||
let result = inductor.induct(&r, ValidatorStatus::PendingActivation);
|
||||
|
||||
@@ -4,4 +4,4 @@ extern crate types;
|
||||
|
||||
mod inductor;
|
||||
|
||||
pub use inductor::{ValidatorInductionError, ValidatorInductor};
|
||||
pub use crate::inductor::{ValidatorInductionError, ValidatorInductor};
|
||||
|
||||
Reference in New Issue
Block a user