From 64dca6fba70b583ae189a3e17952c0d34be87eb2 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 12 Jun 2019 15:40:48 +1000 Subject: [PATCH] committee cache: avoid spurious recomputes Check that the committeee cache matches the absolute epoch for the relative epoch, rather than always checking the previous epoch. --- eth2/types/src/beacon_state.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/eth2/types/src/beacon_state.rs b/eth2/types/src/beacon_state.rs index c4000b8d8..b5dbf2a4a 100644 --- a/eth2/types/src/beacon_state.rs +++ b/eth2/types/src/beacon_state.rs @@ -110,7 +110,9 @@ where pub current_crosslinks: FixedLenVec, pub previous_crosslinks: FixedLenVec, pub latest_block_roots: FixedLenVec, + #[compare_fields(as_slice)] latest_state_roots: FixedLenVec, + #[compare_fields(as_slice)] latest_active_index_roots: FixedLenVec, latest_slashed_balances: FixedLenVec, pub latest_block_header: BeaconBlockHeader, @@ -795,7 +797,9 @@ impl BeaconState { ) -> Result<(), Error> { let i = Self::cache_index(relative_epoch); - if self.committee_caches[i].is_initialized_at(self.previous_epoch()) { + if self.committee_caches[i] + .is_initialized_at(relative_epoch.into_epoch(self.current_epoch())) + { Ok(()) } else { self.force_build_committee_cache(relative_epoch, spec)