Skip to content

Commit

Permalink
Revert Arced pubkey optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion committed Apr 9, 2024
1 parent 2b3b71a commit 84e54bf
Show file tree
Hide file tree
Showing 43 changed files with 186 additions and 668 deletions.
8 changes: 4 additions & 4 deletions account_manager/src/validator/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ async fn publish_voluntary_exit<E: EthSpec>(
let validator_data = get_validator_data(client, &keypair.pk).await?;
match validator_data.status {
ValidatorStatus::ActiveExiting => {
let exit_epoch = validator_data.validator.exit_epoch();
let withdrawal_epoch = validator_data.validator.withdrawable_epoch();
let exit_epoch = validator_data.validator.exit_epoch;
let withdrawal_epoch = validator_data.validator.withdrawable_epoch;
let current_epoch = get_current_epoch::<E>(genesis_data.genesis_time, spec)
.ok_or("Failed to get current epoch. Please check your system time")?;
eprintln!("Voluntary exit has been accepted into the beacon chain, but not yet finalized. \
Expand All @@ -224,7 +224,7 @@ async fn publish_voluntary_exit<E: EthSpec>(
ValidatorStatus::ExitedSlashed | ValidatorStatus::ExitedUnslashed => {
eprintln!(
"Validator has exited on epoch: {}",
validator_data.validator.exit_epoch()
validator_data.validator.exit_epoch
);
break;
}
Expand All @@ -250,7 +250,7 @@ async fn get_validator_index_for_exit(
ValidatorStatus::ActiveOngoing => {
let eligible_epoch = validator_data
.validator
.activation_epoch()
.activation_epoch
.safe_add(spec.shard_committee_period)
.map_err(|e| format!("Failed to calculate eligible epoch, validator activation epoch too high: {:?}", e))?;

Expand Down
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/attestation_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let mut inactivity_penalty = 0i64;

if eligible {
let effective_balance = validator.effective_balance();
let effective_balance = validator.effective_balance;

for flag_index in 0..PARTICIPATION_FLAG_WEIGHTS.len() {
let (ideal_reward, penalty) = ideal_rewards_hashmap
.get(&(flag_index, effective_balance))
.ok_or(BeaconChainError::AttestationRewardsError)?;
let voted_correctly = !validator.slashed()
let voted_correctly = !validator.slashed
&& previous_epoch_participation_flags.has_flag(flag_index)?;
if voted_correctly {
if flag_index == TIMELY_HEAD_FLAG_INDEX {
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/beacon_block_reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
proposer_slashing_reward.safe_add_assign(
state
.get_validator(proposer_slashing.proposer_index() as usize)?
.effective_balance()
.effective_balance
.safe_div(self.spec.whistleblower_reward_quotient)?,
)?;
}
Expand All @@ -157,7 +157,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
attester_slashing_reward.safe_add_assign(
state
.get_validator(attester_index as usize)?
.effective_balance()
.effective_balance
.safe_div(self.spec.whistleblower_reward_quotient)?,
)?;
}
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4809,7 +4809,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let pubkey = state
.validators()
.get(proposer_index as usize)
.map(|v| *v.pubkey())
.map(|v| v.pubkey)
.ok_or(BlockProductionError::BeaconChain(
BeaconChainError::ValidatorIndexUnknown(proposer_index as usize),
))?;
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ fn scrape_head_state<E: EthSpec>(state: &BeaconState<E>, state_root: Hash256) {
num_active += 1;
}

if v.slashed() {
if v.slashed {
num_slashed += 1;
}

Expand Down
16 changes: 8 additions & 8 deletions beacon_node/beacon_chain/src/validator_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,10 @@ impl<E: EthSpec> ValidatorMonitor<E> {
.skip(self.indices.len())
.for_each(|(i, validator)| {
let i = i as u64;
if let Some(validator) = self.validators.get_mut(validator.pubkey()) {
if let Some(validator) = self.validators.get_mut(&validator.pubkey) {
validator.set_index(i)
}
self.indices.insert(i, *validator.pubkey());
self.indices.insert(i, validator.pubkey);
});

// Add missed non-finalized blocks for the monitored validators
Expand Down Expand Up @@ -536,12 +536,12 @@ impl<E: EthSpec> ValidatorMonitor<E> {
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],
i64::from(validator.slashed()),
i64::from(validator.slashed),
);
metrics::set_int_gauge(
&metrics::VALIDATOR_MONITOR_ACTIVE,
Expand All @@ -561,22 +561,22 @@ impl<E: EthSpec> ValidatorMonitor<E> {
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),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/validator_pubkey_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<T: BeaconChainTypes> ValidatorPubkeyCache<T> {
state
.validators()
.iter_from(self.pubkeys.len())?
.map(|v| *v.pubkey),
.map(|v| v.pubkey),
)
} else {
Ok(vec![])
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/genesis/src/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ mod test {
}

for v in state.validators() {
let creds = v.withdrawal_credentials();
let creds = v.withdrawal_credentials;
assert_eq!(
creds.as_bytes()[0],
spec.bls_withdrawal_prefix_byte,
"first byte of withdrawal creds should be bls prefix"
);
assert_eq!(
&creds.as_bytes()[1..],
&hash(&v.pubkey().as_ssz_bytes())[1..],
&hash(&v.pubkey.as_ssz_bytes())[1..],
"rest of withdrawal creds should be pubkey hash"
)
}
Expand Down Expand Up @@ -241,7 +241,7 @@ mod test {
}

for (index, v) in state.validators().iter().enumerate() {
let withdrawal_credientials = v.withdrawal_credentials();
let withdrawal_credientials = v.withdrawal_credentials;
let creds = withdrawal_credientials.as_bytes();
if index % 2 == 0 {
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_api/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn pubkey_to_validator_index<T: BeaconChainTypes>(
state
.validators()
.get(index)
.map_or(false, |v| *v.pubkey == *pubkey)
.map_or(false, |v| v.pubkey == *pubkey)
})
.map(Result::Ok)
.transpose()
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/http_api/src/validator_inclusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,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)?,
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/http_api/src/validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn get_beacon_state_validators<T: BeaconChainTypes>(
.filter(|(index, (validator, _))| {
query_ids.as_ref().map_or(true, |ids| {
ids.iter().any(|id| match id {
ValidatorId::PublicKey(pubkey) => validator.pubkey() == pubkey,
ValidatorId::PublicKey(pubkey) => &validator.pubkey == pubkey,
ValidatorId::Index(param_index) => {
*param_index == *index as u64
}
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn get_beacon_state_validator_balances<T: BeaconChainTypes>(
.filter(|(index, (validator, _))| {
optional_ids.map_or(true, |ids| {
ids.iter().any(|id| match id {
ValidatorId::PublicKey(pubkey) => validator.pubkey() == pubkey,
ValidatorId::PublicKey(pubkey) => &validator.pubkey == pubkey,
ValidatorId::Index(param_index) => {
*param_index == *index as u64
}
Expand Down
8 changes: 4 additions & 4 deletions beacon_node/operation_pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl<E: EthSpec> OperationPool<E> {
&& 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(),
E::MaxProposerSlashings::to_usize(),
Expand Down Expand Up @@ -451,7 +451,7 @@ impl<E: EthSpec> OperationPool<E> {
pub fn prune_proposer_slashings(&self, head_state: &BeaconState<E>) {
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,
);
}
Expand All @@ -470,7 +470,7 @@ impl<E: EthSpec> OperationPool<E> {
//
// 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());

Expand Down Expand Up @@ -527,7 +527,7 @@ impl<E: EthSpec> OperationPool<E> {
//
// 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,
);
}
Expand Down
12 changes: 6 additions & 6 deletions common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,20 +375,20 @@ pub enum ValidatorStatus {
impl ValidatorStatus {
pub fn from_validator(validator: &Validator, epoch: Epoch, far_future_epoch: Epoch) -> Self {
if validator.is_withdrawable_at(epoch) {
if validator.effective_balance() == 0 {
if validator.effective_balance == 0 {
ValidatorStatus::WithdrawalDone
} else {
ValidatorStatus::WithdrawalPossible
}
} else if validator.is_exited_at(epoch) && epoch < validator.withdrawable_epoch() {
if validator.slashed() {
} else if validator.is_exited_at(epoch) && epoch < validator.withdrawable_epoch {
if validator.slashed {
ValidatorStatus::ExitedSlashed
} else {
ValidatorStatus::ExitedUnslashed
}
} else if validator.is_active_at(epoch) {
if validator.exit_epoch() < far_future_epoch {
if validator.slashed() {
if validator.exit_epoch < far_future_epoch {
if validator.slashed {
ValidatorStatus::ActiveSlashed
} else {
ValidatorStatus::ActiveExiting
Expand All @@ -399,7 +399,7 @@ impl ValidatorStatus {
// `pending` statuses are specified as validators where `validator.activation_epoch > current_epoch`.
// If this code is reached, this criteria must have been met because `validator.is_active_at(epoch)`,
// `validator.is_exited_at(epoch)`, and `validator.is_withdrawable_at(epoch)` all returned false.
} else if validator.activation_eligibility_epoch() == far_future_epoch {
} else if validator.activation_eligibility_epoch == far_future_epoch {
ValidatorStatus::PendingInitialized
} else {
ValidatorStatus::PendingQueued
Expand Down
6 changes: 3 additions & 3 deletions consensus/proto_array/src/justified_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ impl JustifiedBalances {
.validators()
.iter()
.map(|validator| {
if !validator.slashed() && validator.is_active_at(current_epoch) {
total_effective_balance.safe_add_assign(validator.effective_balance())?;
if !validator.slashed && validator.is_active_at(current_epoch) {
total_effective_balance.safe_add_assign(validator.effective_balance)?;
num_active_validators.safe_add_assign(1)?;

Ok(validator.effective_balance())
Ok(validator.effective_balance)
} else {
Ok(0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ pub fn initiate_validator_exit<E: EthSpec>(
let validator = state.get_validator_cow(index)?;

// Return if the validator already initiated exit
if validator.exit_epoch() != spec.far_future_epoch {
if validator.exit_epoch != spec.far_future_epoch {
return Ok(());
}

let validator = validator.into_mut()?;
validator.mutable.exit_epoch = exit_queue_epoch;
validator.mutable.withdrawable_epoch =
validator.exit_epoch = exit_queue_epoch;
validator.withdrawable_epoch =
exit_queue_epoch.safe_add(spec.min_validator_withdrawability_delay)?;

state
Expand Down
8 changes: 4 additions & 4 deletions consensus/state_processing/src/common/slash_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ pub fn slash_validator<E: EthSpec>(
initiate_validator_exit(state, slashed_index, spec)?;

let validator = state.get_validator_mut(slashed_index)?;
validator.mutable.slashed = true;
validator.mutable.withdrawable_epoch = cmp::max(
validator.withdrawable_epoch(),
validator.slashed = true;
validator.withdrawable_epoch = cmp::max(
validator.withdrawable_epoch,
epoch.safe_add(E::EpochsPerSlashingsVector::to_u64())?,
);
let validator_effective_balance = validator.effective_balance();
let validator_effective_balance = validator.effective_balance;
state.set_slashings(
epoch,
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn initialize_progressive_balances_cache<E: EthSpec>(
.zip(state.previous_epoch_participation()?)
{
// Exclude slashed validators. We are calculating *unslashed* participating totals.
if validator.slashed() {
if validator.slashed {
continue;
}

Expand Down Expand Up @@ -78,7 +78,7 @@ fn update_flag_total_balances(
) -> Result<(), BeaconStateError> {
for (flag, balance) in total_balances.total_flag_balances.iter_mut().enumerate() {
if participation_flags.has_flag(flag)? {
balance.safe_add_assign(validator.effective_balance())?;
balance.safe_add_assign(validator.effective_balance)?;
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion consensus/state_processing/src/epoch_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn initialize_epoch_cache<E: EthSpec>(
let mut activation_queue = ActivationQueue::default();

for (index, validator) in state.validators().iter().enumerate() {
effective_balances.push(validator.effective_balance());
effective_balances.push(validator.effective_balance);

// Add to speculative activation queue.
activation_queue
Expand Down
8 changes: 4 additions & 4 deletions consensus/state_processing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ pub fn process_activations<E: EthSpec>(
.get(index)
.copied()
.ok_or(Error::BalancesOutOfBounds(index))?;
validator.mutable.effective_balance = std::cmp::min(
validator.effective_balance = std::cmp::min(
balance.safe_sub(balance.safe_rem(spec.effective_balance_increment)?)?,
spec.max_effective_balance,
);
if validator.effective_balance() == spec.max_effective_balance {
validator.mutable.activation_eligibility_epoch = E::genesis_epoch();
validator.mutable.activation_epoch = E::genesis_epoch();
if validator.effective_balance == spec.max_effective_balance {
validator.activation_eligibility_epoch = E::genesis_epoch();
validator.activation_epoch = E::genesis_epoch();
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion consensus/state_processing/src/per_block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub fn process_block_header<E: EthSpec>(

// Verify proposer is not slashed
verify!(
!state.get_validator(proposer_index as usize)?.slashed(),
!state.get_validator(proposer_index as usize)?.slashed,
HeaderInvalid::ProposerSlashed(proposer_index)
);

Expand Down
Loading

0 comments on commit 84e54bf

Please sign in to comment.