Merge remote-tracking branch 'origin/paul-gossip-test' into validator-enhancements

This commit is contained in:
Age Manning 2019-03-31 13:58:38 +11:00
commit b4c21ccca3
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93
2 changed files with 25 additions and 9 deletions

View File

@ -130,10 +130,7 @@ where
state_root, state_root,
)); ));
genesis_state.build_epoch_cache(RelativeEpoch::Previous, &spec)?; genesis_state.build_all_caches(&spec)?;
genesis_state.build_epoch_cache(RelativeEpoch::Current, &spec)?;
genesis_state.build_epoch_cache(RelativeEpoch::NextWithoutRegistryChange, &spec)?;
genesis_state.build_epoch_cache(RelativeEpoch::NextWithRegistryChange, &spec)?;
Ok(Self { Ok(Self {
block_store, block_store,
@ -318,6 +315,8 @@ where
per_slot_processing(&mut state, &latest_block_header, &self.spec)?; per_slot_processing(&mut state, &latest_block_header, &self.spec)?;
} }
state.build_all_caches(&self.spec)?;
*self.state.write() = state; *self.state.write() = state;
Ok(()) Ok(())
@ -342,11 +341,17 @@ where
per_slot_processing(&mut *state, &latest_block_header, &self.spec)?; per_slot_processing(&mut *state, &latest_block_header, &self.spec)?;
} }
state.build_epoch_cache(RelativeEpoch::Previous, &self.spec)?;
state.build_epoch_cache(RelativeEpoch::Current, &self.spec)?; state.build_all_caches(&self.spec)?;
state.build_epoch_cache(RelativeEpoch::NextWithoutRegistryChange, &self.spec)?;
state.build_epoch_cache(RelativeEpoch::NextWithRegistryChange, &self.spec)?; Ok(())
state.update_pubkey_cache()?; }
/// Build all of the caches on the current state.
///
/// Ideally this shouldn't be required, however we leave it here for testing.
pub fn ensure_state_caches_are_built(&self) -> Result<(), Error> {
self.state.write().build_all_caches(&self.spec)?;
Ok(()) Ok(())
} }

View File

@ -661,6 +661,17 @@ impl BeaconState {
}) })
} }
/// Build all the caches, if they need to be built.
pub fn build_all_caches(&mut self, spec: &ChainSpec) -> Result<(), Error> {
self.build_epoch_cache(RelativeEpoch::Previous, spec)?;
self.build_epoch_cache(RelativeEpoch::Current, spec)?;
self.build_epoch_cache(RelativeEpoch::NextWithoutRegistryChange, spec)?;
self.build_epoch_cache(RelativeEpoch::NextWithRegistryChange, spec)?;
self.update_pubkey_cache()?;
Ok(())
}
/// Build an epoch cache, unless it is has already been built. /// Build an epoch cache, unless it is has already been built.
pub fn build_epoch_cache( pub fn build_epoch_cache(
&mut self, &mut self,