Skip to content

Commit

Permalink
clone epoch participation outside of the loop
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed Oct 6, 2023
1 parent 0a70967 commit 1d7cbf0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
10 changes: 7 additions & 3 deletions beacon_node/beacon_chain/src/beacon_block_reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,17 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
)?;

let attesting_indices = get_attesting_indices_from_state(state, attestation)?;

let mut current_epoch_participation = state.current_epoch_participation()?.clone();
let mut previous_epoch_participation = state.previous_epoch_participation()?.clone();
let mut proposer_reward_numerator = 0;
for index in attesting_indices {
let index = index as usize;
for (flag_index, &weight) in PARTICIPATION_FLAG_WEIGHTS.iter().enumerate() {
let mut epoch_participation =
state.get_epoch_participation(data.target.epoch)?.clone();
let epoch_participation = if data.target.epoch == state.current_epoch() {
&mut current_epoch_participation
} else {
&mut previous_epoch_participation
};

let validator_participation = epoch_participation
.get_mut(index)
Expand Down
24 changes: 0 additions & 24 deletions consensus/types/src/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,30 +1398,6 @@ impl<T: EthSpec> BeaconState<T> {
}
}

/// Get a reference to the epoch participation flags for `epoch`.
pub fn get_epoch_participation(
&self,
epoch: Epoch,
) -> Result<&VariableList<ParticipationFlags, T::ValidatorRegistryLimit>, Error> {
if epoch == self.current_epoch() {
match self {
BeaconState::Base(_) => Err(BeaconStateError::IncorrectStateVariant),
BeaconState::Altair(state) => Ok(&state.current_epoch_participation),
BeaconState::Merge(state) => Ok(&state.current_epoch_participation),
BeaconState::Capella(state) => Ok(&state.current_epoch_participation),
}
} else if epoch == self.previous_epoch() {
match self {
BeaconState::Base(_) => Err(BeaconStateError::IncorrectStateVariant),
BeaconState::Altair(state) => Ok(&state.previous_epoch_participation),
BeaconState::Merge(state) => Ok(&state.previous_epoch_participation),
BeaconState::Capella(state) => Ok(&state.previous_epoch_participation),
}
} else {
Err(BeaconStateError::EpochOutOfBounds)
}
}

/// Get the number of outstanding deposits.
///
/// Returns `Err` if the state is invalid.
Expand Down

0 comments on commit 1d7cbf0

Please sign in to comment.