Split validator into ValidatorMutable

This commit is contained in:
Michael Sproul
2022-09-28 11:43:58 +10:00
parent 9ec454aa52
commit 9a1799f235
22 changed files with 133 additions and 97 deletions

View File

@@ -52,7 +52,7 @@ pub fn get_effective_balances<T: EthSpec>(state: &BeaconState<T>) -> Vec<u64> {
.iter()
.map(|validator| {
if validator.is_active_at(state.current_epoch()) {
validator.effective_balance
validator.effective_balance()
} else {
0
}

View File

@@ -1084,7 +1084,7 @@ fn scrape_head_state<T: EthSpec>(state: &BeaconState<T>, state_root: Hash256) {
num_active += 1;
}
if v.slashed {
if v.slashed() {
num_slashed += 1;
}

View File

@@ -327,12 +327,12 @@ impl<T: EthSpec> ValidatorMonitor<T> {
metrics::set_int_gauge(
&metrics::VALIDATOR_MONITOR_EFFECTIVE_BALANCE_GWEI,
&[id],
u64_to_i64(validator.effective_balance),
u64_to_i64(validator.effective_balance()),
);
metrics::set_int_gauge(
&metrics::VALIDATOR_MONITOR_SLASHED,
&[id],
if validator.slashed { 1 } else { 0 },
if validator.slashed() { 1 } else { 0 },
);
metrics::set_int_gauge(
&metrics::VALIDATOR_MONITOR_ACTIVE,
@@ -364,22 +364,22 @@ impl<T: EthSpec> ValidatorMonitor<T> {
metrics::set_int_gauge(
&metrics::VALIDATOR_ACTIVATION_ELIGIBILITY_EPOCH,
&[id],
u64_to_i64(validator.activation_eligibility_epoch),
u64_to_i64(validator.activation_eligibility_epoch()),
);
metrics::set_int_gauge(
&metrics::VALIDATOR_ACTIVATION_EPOCH,
&[id],
u64_to_i64(validator.activation_epoch),
u64_to_i64(validator.activation_epoch()),
);
metrics::set_int_gauge(
&metrics::VALIDATOR_EXIT_EPOCH,
&[id],
u64_to_i64(validator.exit_epoch),
u64_to_i64(validator.exit_epoch()),
);
metrics::set_int_gauge(
&metrics::VALIDATOR_WITHDRAWABLE_EPOCH,
&[id],
u64_to_i64(validator.withdrawable_epoch),
u64_to_i64(validator.withdrawable_epoch()),
);
}
}

View File

@@ -99,13 +99,13 @@ pub fn validator_inclusion_data<T: BeaconChainTypes>(
let summary = get_epoch_processing_summary(&mut state, &chain.spec)?;
Ok(Some(ValidatorInclusionData {
is_slashed: validator.slashed,
is_slashed: validator.slashed(),
is_withdrawable_in_current_epoch: validator.is_withdrawable_at(epoch),
is_active_unslashed_in_current_epoch: summary
.is_active_unslashed_in_current_epoch(validator_index),
is_active_unslashed_in_previous_epoch: summary
.is_active_unslashed_in_previous_epoch(validator_index),
current_epoch_effective_balance_gwei: validator.effective_balance,
current_epoch_effective_balance_gwei: validator.effective_balance(),
is_current_epoch_target_attester: summary
.is_current_epoch_target_attester(validator_index)
.map_err(convert_cache_error)?,

View File

@@ -370,7 +370,7 @@ impl<T: EthSpec> OperationPool<T> {
&& state
.validators()
.get(slashing.as_inner().signed_header_1.message.proposer_index as usize)
.map_or(false, |validator| !validator.slashed)
.map_or(false, |validator| !validator.slashed())
},
|slashing| slashing.as_inner().clone(),
T::MaxProposerSlashings::to_usize(),
@@ -429,7 +429,7 @@ impl<T: EthSpec> OperationPool<T> {
pub fn prune_proposer_slashings(&self, head_state: &BeaconState<T>) {
prune_validator_hash_map(
&mut self.proposer_slashings.write(),
|validator| validator.exit_epoch <= head_state.finalized_checkpoint().epoch,
|validator| validator.exit_epoch() <= head_state.finalized_checkpoint().epoch,
head_state,
);
}
@@ -448,7 +448,7 @@ impl<T: EthSpec> OperationPool<T> {
//
// We cannot check the `slashed` field since the `head` is not finalized and
// a fork could un-slash someone.
validator.exit_epoch > head_state.finalized_checkpoint().epoch
validator.exit_epoch() > head_state.finalized_checkpoint().epoch
})
.map_or(false, |indices| !indices.is_empty());
@@ -504,7 +504,7 @@ impl<T: EthSpec> OperationPool<T> {
//
// We choose simplicity over the gain of pruning more exits since they are small and
// should not be seen frequently.
|validator| validator.exit_epoch <= head_state.finalized_checkpoint().epoch,
|validator| validator.exit_epoch() <= head_state.finalized_checkpoint().epoch,
head_state,
);
}