Optimization: avoid recomputing known state roots (#762)

* Start adding optimization

* Add temp fix for protobuf issue

* Fix compile errors

* Fix protobuf import
This commit is contained in:
Paul Hauner
2020-01-03 15:09:00 +11:00
committed by GitHub
parent 39df89521f
commit 647034b637
11 changed files with 42 additions and 16 deletions

View File

@@ -515,7 +515,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
});
}
match per_slot_processing(&mut state, &self.spec) {
// Note: supplying some `state_root` when it is known would be a cheap and easy
// optimization.
match per_slot_processing(&mut state, None, &self.spec) {
Ok(()) => (),
Err(e) => {
warn!(
@@ -887,7 +889,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.start_slot(T::EthSpec::slots_per_epoch())
.as_u64()
{
per_slot_processing(&mut state, &self.spec)?;
per_slot_processing(&mut state, None, &self.spec)?;
}
state.build_committee_cache(RelativeEpoch::Current, &self.spec)?;
@@ -1258,7 +1260,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
if i > 0 {
intermediate_states.push(state.clone());
}
per_slot_processing(&mut state, &self.spec)?;
let state_root = if i == 0 {
Some(parent_block.state_root)
} else {
None
};
per_slot_processing(&mut state, state_root, &self.spec)?;
}
metrics::stop_timer(catchup_timer);
@@ -1426,8 +1435,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.ok_or_else(|| BlockProductionError::NoEth1ChainConnection)?;
// If required, transition the new state to the present slot.
//
// Note: supplying some `state_root` when it it is known would be a cheap and easy
// optimization.
while state.slot < produce_at_slot {
per_slot_processing(&mut state, &self.spec)?;
per_slot_processing(&mut state, None, &self.spec)?;
}
state.build_committee_cache(RelativeEpoch::Current, &self.spec)?;