mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 21:04:41 +00:00
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:
@@ -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)?;
|
||||
|
||||
@@ -155,7 +155,7 @@ impl<T: BeaconChainTypes> ForkChoice<T> {
|
||||
|
||||
// Fast-forward the state to the start slot of the epoch where it was justified.
|
||||
for _ in block.slot.as_u64()..block_justified_slot.as_u64() {
|
||||
per_slot_processing(&mut state, &chain.spec)
|
||||
per_slot_processing(&mut state, None, &chain.spec)
|
||||
.map_err(BeaconChainError::SlotProcessingError)?
|
||||
}
|
||||
|
||||
|
||||
@@ -287,7 +287,7 @@ where
|
||||
}
|
||||
|
||||
while state.slot < slot {
|
||||
per_slot_processing(&mut state, &self.spec)
|
||||
per_slot_processing(&mut state, None, &self.spec)
|
||||
.expect("should be able to advance state to slot");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user