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 10, 2024
1 parent 2b3b71a commit 8b6ecdd
Show file tree
Hide file tree
Showing 49 changed files with 220 additions and 718 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
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,15 +1282,15 @@ mod test {
}

for v in state.validators() {
let creds = v.withdrawal_credentials();
let creds = v.withdrawal_credentials;
let creds = creds.as_bytes();
assert_eq!(
creds[0], spec.bls_withdrawal_prefix_byte,
"first byte of withdrawal creds should be bls prefix"
);
assert_eq!(
&creds[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
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
30 changes: 17 additions & 13 deletions beacon_node/beacon_chain/tests/op_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async fn voluntary_exit_duplicate_in_state() {
.validators()
.get(exited_validator as usize)
.unwrap()
.exit_epoch(),
.exit_epoch,
spec.far_future_epoch
);

Expand Down Expand Up @@ -274,12 +274,14 @@ async fn proposer_slashing_duplicate_in_state() {
.await;

// Verify validator is actually slashed.
assert!(harness
.get_current_state()
.validators()
.get(slashed_validator as usize)
.unwrap()
.slashed());
assert!(
harness
.get_current_state()
.validators()
.get(slashed_validator as usize)
.unwrap()
.slashed
);

// Clear the in-memory gossip cache & try to verify the same slashing on gossip.
// It should still fail because gossip verification should check the validator's `slashed` field
Expand Down Expand Up @@ -400,12 +402,14 @@ async fn attester_slashing_duplicate_in_state() {
.await;

// Verify validator is actually slashed.
assert!(harness
.get_current_state()
.validators()
.get(slashed_validator as usize)
.unwrap()
.slashed());
assert!(
harness
.get_current_state()
.validators()
.get(slashed_validator as usize)
.unwrap()
.slashed
);

// Clear the in-memory gossip cache & try to verify the same slashing on gossip.
// It should still fail because gossip verification should check the validator's `slashed` field
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/tests/payload_invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ async fn weights_after_resetting_optimistic_status() {
.fork_choice_read_lock()
.get_block_weight(&head.head_block_root())
.unwrap(),
head.snapshot.beacon_state.validators().get(0).unwrap().effective_balance(),
head.snapshot.beacon_state.validators().get(0).unwrap().effective_balance,
"proposer boost should be removed from the head block and the vote of a single validator applied"
);

Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/tests/store_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ async fn block_replayer_hooks() {
let mut post_block_slots = vec![];

let mut replay_state = BlockReplayer::<MinimalEthSpec>::new(state, &chain.spec)
.pre_slot_hook(Box::new(|state| {
.pre_slot_hook(Box::new(|_, state| {
pre_slots.push(state.slot());
Ok(())
}))
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
10 changes: 5 additions & 5 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ impl ApiTester {
ValidatorId::PublicKey(
validators
.get(i as usize)
.map_or(PublicKeyBytes::empty(), |val| *val.pubkey),
.map_or(PublicKeyBytes::empty(), |val| val.pubkey),
)
})
.collect::<Vec<ValidatorId>>();
Expand Down Expand Up @@ -907,7 +907,7 @@ impl ApiTester {
ValidatorId::PublicKey(
validators
.get(i as usize)
.map_or(PublicKeyBytes::empty(), |val| *val.pubkey),
.map_or(PublicKeyBytes::empty(), |val| val.pubkey),
)
})
.collect::<Vec<ValidatorId>>();
Expand Down Expand Up @@ -1001,7 +1001,7 @@ impl ApiTester {

for (i, validator) in validators.into_iter().enumerate() {
let validator_ids = &[
ValidatorId::PublicKey(*validator.pubkey),
ValidatorId::PublicKey(validator.pubkey),
ValidatorId::Index(i as u64),
];

Expand Down Expand Up @@ -2360,7 +2360,7 @@ impl ApiTester {
.unwrap()
{
let expected = AttesterData {
pubkey: *state.validators().get(i as usize).unwrap().pubkey,
pubkey: state.validators().get(i as usize).unwrap().pubkey,
validator_index: i,
committees_at_slot: duty.committees_at_slot,
committee_index: duty.index,
Expand Down Expand Up @@ -2465,7 +2465,7 @@ impl ApiTester {
let index = state
.get_beacon_proposer_index(slot, &self.chain.spec)
.unwrap();
let pubkey = *state.validators().get(index).unwrap().pubkey;
let pubkey = state.validators().get(index).unwrap().pubkey;

ProposerData {
pubkey,
Expand Down
Loading

0 comments on commit 8b6ecdd

Please sign in to comment.