Finailized updating structs / types to match specs as at 16.1.19
This commit is contained in:
parent
b39f7ac6c2
commit
fe107616ce
@ -51,12 +51,9 @@ impl ChainSpec {
|
|||||||
min_attestation_inclusion_delay: 4,
|
min_attestation_inclusion_delay: 4,
|
||||||
epoch_length: 64,
|
epoch_length: 64,
|
||||||
seed_lookahead: 64,
|
seed_lookahead: 64,
|
||||||
min_validator_registry_change_interval: 256,
|
entry_exit_delay: 256,
|
||||||
pow_receipt_root_voting_period: 1_024,
|
pow_receipt_root_voting_period: 1_024,
|
||||||
min_validator_withdrawal_time: u64::pow(2, 14),
|
min_validator_withdrawal_time: u64::pow(2, 14),
|
||||||
shard_persistent_committee_change_period: u64::pow(2, 17), // old
|
|
||||||
collective_penalty_calculation_period: u64::pow(2, 20), // old
|
|
||||||
zero_balance_validator_ttl: u64::pow(2, 22), // old
|
|
||||||
/*
|
/*
|
||||||
* Reward and penalty quotients
|
* Reward and penalty quotients
|
||||||
*/
|
*/
|
||||||
@ -64,11 +61,6 @@ impl ChainSpec {
|
|||||||
whistleblower_reward_quotient: 512,
|
whistleblower_reward_quotient: 512,
|
||||||
includer_reward_quotient: 8,
|
includer_reward_quotient: 8,
|
||||||
inactivity_penalty_quotient: u64::pow(2, 24),
|
inactivity_penalty_quotient: u64::pow(2, 24),
|
||||||
/*
|
|
||||||
* Status flags
|
|
||||||
*/
|
|
||||||
initiated_exit: 1,
|
|
||||||
withdrawable: 2,
|
|
||||||
/*
|
/*
|
||||||
* Max operations per block
|
* Max operations per block
|
||||||
*/
|
*/
|
||||||
@ -77,18 +69,6 @@ impl ChainSpec {
|
|||||||
max_attestations: 128,
|
max_attestations: 128,
|
||||||
max_deposits: 16,
|
max_deposits: 16,
|
||||||
max_exits: 16,
|
max_exits: 16,
|
||||||
/*
|
|
||||||
* Validator registry delta flags
|
|
||||||
*/
|
|
||||||
activation: 0,
|
|
||||||
exit: 1,
|
|
||||||
/*
|
|
||||||
* Signature domains
|
|
||||||
*/
|
|
||||||
domain_deposit: 0,
|
|
||||||
domain_attestation: 1,
|
|
||||||
domain_proposal: 2,
|
|
||||||
domain_exit: 3,
|
|
||||||
/*
|
/*
|
||||||
* Intialization parameters
|
* Intialization parameters
|
||||||
*/
|
*/
|
||||||
@ -133,9 +113,8 @@ fn initial_validators_for_testing() -> Vec<ValidatorRecord> {
|
|||||||
exit_slot: u64::max_value(),
|
exit_slot: u64::max_value(),
|
||||||
withdrawal_slot: u64::max_value(),
|
withdrawal_slot: u64::max_value(),
|
||||||
penalized_slot: u64::max_value(),
|
penalized_slot: u64::max_value(),
|
||||||
status: From::from(0),
|
|
||||||
latest_status_change_slot: 0,
|
|
||||||
exit_count: 0,
|
exit_count: 0,
|
||||||
|
status: From::from(0),
|
||||||
custody_commitment: Hash256::zero(),
|
custody_commitment: Hash256::zero(),
|
||||||
latest_custody_reseed_slot: 0,
|
latest_custody_reseed_slot: 0,
|
||||||
penultimate_custody_reseed_slot: 0,
|
penultimate_custody_reseed_slot: 0,
|
||||||
|
@ -46,12 +46,9 @@ pub struct ChainSpec {
|
|||||||
pub min_attestation_inclusion_delay: u64,
|
pub min_attestation_inclusion_delay: u64,
|
||||||
pub epoch_length: u64,
|
pub epoch_length: u64,
|
||||||
pub seed_lookahead: u64,
|
pub seed_lookahead: u64,
|
||||||
pub min_validator_registry_change_interval: u64, // a.k.a. entry_exit_delay
|
pub entry_exit_delay: u64,
|
||||||
pub pow_receipt_root_voting_period: u64, // a.k. deposit_root_voting_period
|
pub pow_receipt_root_voting_period: u64, // a.k.a. deposit_root_voting_period
|
||||||
pub min_validator_withdrawal_time: u64,
|
pub min_validator_withdrawal_time: u64,
|
||||||
pub shard_persistent_committee_change_period: u64, //old
|
|
||||||
pub collective_penalty_calculation_period: u64, // old
|
|
||||||
pub zero_balance_validator_ttl: u64, // old
|
|
||||||
/*
|
/*
|
||||||
* Reward and penalty quotients
|
* Reward and penalty quotients
|
||||||
*/
|
*/
|
||||||
@ -59,11 +56,6 @@ pub struct ChainSpec {
|
|||||||
pub whistleblower_reward_quotient: u64,
|
pub whistleblower_reward_quotient: u64,
|
||||||
pub includer_reward_quotient: u64,
|
pub includer_reward_quotient: u64,
|
||||||
pub inactivity_penalty_quotient: u64,
|
pub inactivity_penalty_quotient: u64,
|
||||||
/*
|
|
||||||
* Status flags
|
|
||||||
*/
|
|
||||||
pub initiated_exit: u64,
|
|
||||||
pub withdrawable: u64,
|
|
||||||
/*
|
/*
|
||||||
* Max operations per block
|
* Max operations per block
|
||||||
*/
|
*/
|
||||||
@ -72,18 +64,6 @@ pub struct ChainSpec {
|
|||||||
pub max_attestations: u64,
|
pub max_attestations: u64,
|
||||||
pub max_deposits: u64,
|
pub max_deposits: u64,
|
||||||
pub max_exits: u64,
|
pub max_exits: u64,
|
||||||
/*
|
|
||||||
* Validator registry delta flags
|
|
||||||
*/
|
|
||||||
pub activation: u64,
|
|
||||||
pub exit: u64,
|
|
||||||
/*
|
|
||||||
* Signature domains
|
|
||||||
*/
|
|
||||||
pub domain_deposit: u64,
|
|
||||||
pub domain_attestation: u64,
|
|
||||||
pub domain_proposal: u64,
|
|
||||||
pub domain_exit: u64,
|
|
||||||
/*
|
/*
|
||||||
* Intialization parameters
|
* Intialization parameters
|
||||||
*/
|
*/
|
||||||
|
@ -39,9 +39,8 @@ pub struct ValidatorRecord {
|
|||||||
pub exit_slot: u64,
|
pub exit_slot: u64,
|
||||||
pub withdrawal_slot: u64,
|
pub withdrawal_slot: u64,
|
||||||
pub penalized_slot: u64,
|
pub penalized_slot: u64,
|
||||||
pub status: ValidatorStatus,
|
|
||||||
pub latest_status_change_slot: u64,
|
|
||||||
pub exit_count: u64,
|
pub exit_count: u64,
|
||||||
|
pub status: ValidatorStatus,
|
||||||
pub custody_commitment: Hash256,
|
pub custody_commitment: Hash256,
|
||||||
pub latest_custody_reseed_slot: u64,
|
pub latest_custody_reseed_slot: u64,
|
||||||
pub penultimate_custody_reseed_slot: u64,
|
pub penultimate_custody_reseed_slot: u64,
|
||||||
@ -107,9 +106,8 @@ impl Encodable for ValidatorRecord {
|
|||||||
s.append(&self.exit_slot);
|
s.append(&self.exit_slot);
|
||||||
s.append(&self.withdrawal_slot);
|
s.append(&self.withdrawal_slot);
|
||||||
s.append(&self.penalized_slot);
|
s.append(&self.penalized_slot);
|
||||||
s.append(&self.status);
|
|
||||||
s.append(&self.latest_status_change_slot);
|
|
||||||
s.append(&self.exit_count);
|
s.append(&self.exit_count);
|
||||||
|
s.append(&self.status);
|
||||||
s.append(&self.custody_commitment);
|
s.append(&self.custody_commitment);
|
||||||
s.append(&self.latest_custody_reseed_slot);
|
s.append(&self.latest_custody_reseed_slot);
|
||||||
s.append(&self.penultimate_custody_reseed_slot);
|
s.append(&self.penultimate_custody_reseed_slot);
|
||||||
@ -126,9 +124,8 @@ impl Decodable for ValidatorRecord {
|
|||||||
let (exit_slot, i) = <_>::ssz_decode(bytes, i)?;
|
let (exit_slot, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (withdrawal_slot, i) = <_>::ssz_decode(bytes, i)?;
|
let (withdrawal_slot, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (penalized_slot, i) = <_>::ssz_decode(bytes, i)?;
|
let (penalized_slot, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (status, i) = <_>::ssz_decode(bytes, i)?;
|
|
||||||
let (latest_status_change_slot, i) = <_>::ssz_decode(bytes, i)?;
|
|
||||||
let (exit_count, i) = <_>::ssz_decode(bytes, i)?;
|
let (exit_count, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
|
let (status, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (custody_commitment, i) = <_>::ssz_decode(bytes, i)?;
|
let (custody_commitment, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (latest_custody_reseed_slot, i) = <_>::ssz_decode(bytes, i)?;
|
let (latest_custody_reseed_slot, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
let (penultimate_custody_reseed_slot, i) = <_>::ssz_decode(bytes, i)?;
|
let (penultimate_custody_reseed_slot, i) = <_>::ssz_decode(bytes, i)?;
|
||||||
@ -143,9 +140,8 @@ impl Decodable for ValidatorRecord {
|
|||||||
exit_slot,
|
exit_slot,
|
||||||
withdrawal_slot,
|
withdrawal_slot,
|
||||||
penalized_slot,
|
penalized_slot,
|
||||||
status,
|
|
||||||
latest_status_change_slot,
|
|
||||||
exit_count,
|
exit_count,
|
||||||
|
status,
|
||||||
custody_commitment,
|
custody_commitment,
|
||||||
latest_custody_reseed_slot,
|
latest_custody_reseed_slot,
|
||||||
penultimate_custody_reseed_slot,
|
penultimate_custody_reseed_slot,
|
||||||
@ -166,9 +162,8 @@ impl<T: RngCore> TestRandom<T> for ValidatorRecord {
|
|||||||
exit_slot: <_>::random_for_test(rng),
|
exit_slot: <_>::random_for_test(rng),
|
||||||
withdrawal_slot: <_>::random_for_test(rng),
|
withdrawal_slot: <_>::random_for_test(rng),
|
||||||
penalized_slot: <_>::random_for_test(rng),
|
penalized_slot: <_>::random_for_test(rng),
|
||||||
status: <_>::random_for_test(rng),
|
|
||||||
latest_status_change_slot: <_>::random_for_test(rng),
|
|
||||||
exit_count: <_>::random_for_test(rng),
|
exit_count: <_>::random_for_test(rng),
|
||||||
|
status: <_>::random_for_test(rng),
|
||||||
custody_commitment: <_>::random_for_test(rng),
|
custody_commitment: <_>::random_for_test(rng),
|
||||||
latest_custody_reseed_slot: <_>::random_for_test(rng),
|
latest_custody_reseed_slot: <_>::random_for_test(rng),
|
||||||
penultimate_custody_reseed_slot: <_>::random_for_test(rng),
|
penultimate_custody_reseed_slot: <_>::random_for_test(rng),
|
||||||
|
@ -13,7 +13,7 @@ pub fn process_deposit(
|
|||||||
state: &mut BeaconState,
|
state: &mut BeaconState,
|
||||||
deposit: &Deposit,
|
deposit: &Deposit,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Result<usize, ValidatorInductionError> {
|
) -> Result<(), ValidatorInductionError> {
|
||||||
let deposit_input = &deposit.deposit_data.deposit_input;
|
let deposit_input = &deposit.deposit_data.deposit_input;
|
||||||
let deposit_data = &deposit.deposit_data;
|
let deposit_data = &deposit.deposit_data;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ pub fn process_deposit(
|
|||||||
== deposit_input.withdrawal_credentials
|
== deposit_input.withdrawal_credentials
|
||||||
{
|
{
|
||||||
state.validator_balances[i] += deposit_data.value;
|
state.validator_balances[i] += deposit_data.value;
|
||||||
return Ok(i);
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(ValidatorInductionError::InvalidWithdrawalCredentials)
|
Err(ValidatorInductionError::InvalidWithdrawalCredentials)
|
||||||
@ -48,41 +48,19 @@ pub fn process_deposit(
|
|||||||
exit_slot: spec.far_future_slot,
|
exit_slot: spec.far_future_slot,
|
||||||
withdrawal_slot: spec.far_future_slot,
|
withdrawal_slot: spec.far_future_slot,
|
||||||
penalized_slot: spec.far_future_slot,
|
penalized_slot: spec.far_future_slot,
|
||||||
status: ValidatorStatus::PendingActivation,
|
|
||||||
latest_status_change_slot: state.validator_registry_latest_change_slot,
|
|
||||||
exit_count: 0,
|
exit_count: 0,
|
||||||
|
status: ValidatorStatus::PendingActivation,
|
||||||
custody_commitment: deposit_input.custody_commitment,
|
custody_commitment: deposit_input.custody_commitment,
|
||||||
latest_custody_reseed_slot: 0,
|
latest_custody_reseed_slot: 0,
|
||||||
penultimate_custody_reseed_slot: 0,
|
penultimate_custody_reseed_slot: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
match min_empty_validator_index(state, spec) {
|
let _index = state.validator_registry.len();
|
||||||
Some(i) => {
|
|
||||||
state.validator_registry[i] = validator;
|
|
||||||
state.validator_balances[i] = deposit_data.value;
|
|
||||||
Ok(i)
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
state.validator_registry.push(validator);
|
state.validator_registry.push(validator);
|
||||||
state.validator_balances.push(deposit_data.value);
|
state.validator_balances.push(deposit_data.value);
|
||||||
Ok(state.validator_registry.len() - 1)
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn min_empty_validator_index(state: &BeaconState, spec: &ChainSpec) -> Option<usize> {
|
|
||||||
for i in 0..state.validator_registry.len() {
|
|
||||||
if state.validator_balances[i] == 0
|
|
||||||
&& state.validator_registry[i].latest_status_change_slot
|
|
||||||
+ spec.zero_balance_validator_ttl
|
|
||||||
<= state.slot
|
|
||||||
{
|
|
||||||
return Some(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -129,7 +107,7 @@ mod tests {
|
|||||||
|
|
||||||
let result = process_deposit(&mut state, &deposit, &spec);
|
let result = process_deposit(&mut state, &deposit, &spec);
|
||||||
|
|
||||||
assert_eq!(result.unwrap(), 0);
|
assert_eq!(result.unwrap(), ());
|
||||||
assert!(deposit_equals_record(
|
assert!(deposit_equals_record(
|
||||||
&deposit,
|
&deposit,
|
||||||
&state.validator_registry[0]
|
&state.validator_registry[0]
|
||||||
@ -147,7 +125,7 @@ mod tests {
|
|||||||
let mut deposit = get_deposit();
|
let mut deposit = get_deposit();
|
||||||
let result = process_deposit(&mut state, &deposit, &spec);
|
let result = process_deposit(&mut state, &deposit, &spec);
|
||||||
deposit.deposit_data.value = DEPOSIT_GWEI;
|
deposit.deposit_data.value = DEPOSIT_GWEI;
|
||||||
assert_eq!(result.unwrap(), i);
|
assert_eq!(result.unwrap(), ());
|
||||||
assert!(deposit_equals_record(
|
assert!(deposit_equals_record(
|
||||||
&deposit,
|
&deposit,
|
||||||
&state.validator_registry[i]
|
&state.validator_registry[i]
|
||||||
@ -176,7 +154,7 @@ mod tests {
|
|||||||
|
|
||||||
let result = process_deposit(&mut state, &deposit, &spec);
|
let result = process_deposit(&mut state, &deposit, &spec);
|
||||||
|
|
||||||
assert_eq!(result.unwrap(), 0);
|
assert_eq!(result.unwrap(), ());
|
||||||
assert!(deposit_equals_record(
|
assert!(deposit_equals_record(
|
||||||
&deposit,
|
&deposit,
|
||||||
&state.validator_registry[0]
|
&state.validator_registry[0]
|
||||||
@ -186,32 +164,6 @@ mod tests {
|
|||||||
assert_eq!(state.validator_balances.len(), 1);
|
assert_eq!(state.validator_balances.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_process_deposit_replace_validator() {
|
|
||||||
let mut state = BeaconState::default();
|
|
||||||
let spec = ChainSpec::foundation();
|
|
||||||
|
|
||||||
let mut validator = get_validator();
|
|
||||||
validator.latest_status_change_slot = 0;
|
|
||||||
state.validator_registry.push(validator);
|
|
||||||
state.validator_balances.push(0);
|
|
||||||
|
|
||||||
let mut deposit = get_deposit();
|
|
||||||
deposit.deposit_data.value = DEPOSIT_GWEI;
|
|
||||||
state.slot = spec.zero_balance_validator_ttl;
|
|
||||||
|
|
||||||
let result = process_deposit(&mut state, &deposit, &spec);
|
|
||||||
|
|
||||||
assert_eq!(result.unwrap(), 0);
|
|
||||||
assert!(deposit_equals_record(
|
|
||||||
&deposit,
|
|
||||||
&state.validator_registry[0]
|
|
||||||
));
|
|
||||||
assert_eq!(state.validator_balances[0], DEPOSIT_GWEI);
|
|
||||||
assert_eq!(state.validator_registry.len(), 1);
|
|
||||||
assert_eq!(state.validator_balances.len(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_process_deposit_invalid_proof_of_possession() {
|
fn test_process_deposit_invalid_proof_of_possession() {
|
||||||
let mut state = BeaconState::default();
|
let mut state = BeaconState::default();
|
||||||
|
Loading…
Reference in New Issue
Block a user