diff --git a/beacon_chain/types/src/validator_record.rs b/beacon_chain/types/src/validator_record.rs index bc0b6b6b5..7077d87e2 100644 --- a/beacon_chain/types/src/validator_record.rs +++ b/beacon_chain/types/src/validator_record.rs @@ -4,6 +4,7 @@ use crate::test_utils::TestRandom; use rand::RngCore; use ssz::{Decodable, DecodeError, Encodable, SszStream}; use std::convert; +use std::default; const STATUS_FLAG_INITIATED_EXIT: u8 = 1; const STATUS_FLAG_WITHDRAWABLE: u8 = 2; @@ -41,6 +42,26 @@ pub struct ValidatorRecord { pub penultimate_custody_reseed_slot: u64, } +impl default::Default for ValidatorRecord { + fn default() -> Self { + Self { + pubkey: PublicKey::default(), + withdrawal_credentials: Hash256::default(), + randao_commitment: Hash256::default(), + randao_layers: 0, + activation_slot: std::u64::MAX, + exit_slot: std::u64::MAX, + withdrawal_slot: std::u64::MAX, + penalized_slot: std::u64::MAX, + exit_count: 0, + status_flags: None, + custody_commitment: Hash256::default(), + latest_custody_reseed_slot: 0, // NOTE: is `GENESIS_SLOT` + penultimate_custody_reseed_slot: 0, // NOTE: is `GENESIS_SLOT` + } + } +} + impl Encodable for StatusFlags { fn ssz_append(&self, s: &mut SszStream) { let byte: u8 = match self { @@ -142,15 +163,12 @@ impl TestRandom for ValidatorRecord { withdrawal_credentials: <_>::random_for_test(rng), randao_commitment: <_>::random_for_test(rng), randao_layers: <_>::random_for_test(rng), - activation_slot: <_>::random_for_test(rng), - exit_slot: <_>::random_for_test(rng), - withdrawal_slot: <_>::random_for_test(rng), - penalized_slot: <_>::random_for_test(rng), exit_count: <_>::random_for_test(rng), status_flags: Some(<_>::random_for_test(rng)), custody_commitment: <_>::random_for_test(rng), latest_custody_reseed_slot: <_>::random_for_test(rng), penultimate_custody_reseed_slot: <_>::random_for_test(rng), + ..Self::default() } } } diff --git a/beacon_chain/utils/bls/src/public_key.rs b/beacon_chain/utils/bls/src/public_key.rs index 49dbc9e4b..e7950969e 100644 --- a/beacon_chain/utils/bls/src/public_key.rs +++ b/beacon_chain/utils/bls/src/public_key.rs @@ -1,6 +1,7 @@ use super::SecretKey; use bls_aggregates::PublicKey as RawPublicKey; use ssz::{decode_ssz_list, Decodable, DecodeError, Encodable, SszStream}; +use std::default; /// A single BLS signature. /// @@ -20,6 +21,13 @@ impl PublicKey { } } +impl default::Default for PublicKey { + fn default() -> Self { + let secret_key = SecretKey::random(); + PublicKey::from_secret_key(&secret_key) + } +} + impl Encodable for PublicKey { fn ssz_append(&self, s: &mut SszStream) { s.append_vec(&self.0.as_bytes());