Skip to content

Commit

Permalink
state_processing: fix slot bug in committee update
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Jul 25, 2019
1 parent 5635742 commit 531ce00
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions eth2/state_processing/src/per_epoch_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ pub fn per_epoch_processing<T: EthSpec>(
state: &mut BeaconState<T>,
spec: &ChainSpec,
) -> Result<(), Error> {
// Ensure the previous and next epoch caches are built.
// Ensure the committee caches are built.
state.build_committee_cache(RelativeEpoch::Previous, spec)?;
state.build_committee_cache(RelativeEpoch::Current, spec)?;
state.build_committee_cache(RelativeEpoch::Next, spec)?;

// Load the struct we use to assign validators into sets based on their participation.
//
Expand Down Expand Up @@ -236,13 +237,6 @@ pub fn process_final_updates<T: EthSpec>(
spec,
)?;

// Set committees root
state.set_compact_committee_root(
next_epoch,
get_compact_committees_root(state, RelativeEpoch::Next, spec)?,
spec,
)?;

// Reset slashings
state.set_slashings(next_epoch, 0)?;

Expand All @@ -252,6 +246,16 @@ pub fn process_final_updates<T: EthSpec>(
state.slot -= 1;
}

// Set committees root
// Note: we do this out-of-order w.r.t. to the spec, because we don't want the slot to be
// incremented. It's safe because the updates to slashings and the RANDAO mix (above) don't
// affect this.
state.set_compact_committee_root(
next_epoch,
get_compact_committees_root(state, RelativeEpoch::Next, spec)?,
spec,
)?;

// Set historical root accumulator
if next_epoch.as_u64() % (T::SlotsPerHistoricalRoot::to_u64() / T::slots_per_epoch()) == 0 {
let historical_batch = state.historical_batch();
Expand Down

0 comments on commit 531ce00

Please sign in to comment.