mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 22:04:44 +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");
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ fn massive_skips() {
|
||||
|
||||
// Run per_slot_processing until it returns an error.
|
||||
let error = loop {
|
||||
match per_slot_processing(&mut state, spec) {
|
||||
match per_slot_processing(&mut state, None, spec) {
|
||||
Ok(_) => continue,
|
||||
Err(e) => break e,
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ pub fn state_root_at_slot<T: BeaconChainTypes>(
|
||||
// Ensure the next epoch state caches are built in case of an epoch transition.
|
||||
state.build_committee_cache(RelativeEpoch::Next, spec)?;
|
||||
|
||||
state_processing::per_slot_processing(&mut state, spec)?;
|
||||
state_processing::per_slot_processing(&mut state, None, spec)?;
|
||||
}
|
||||
|
||||
// Note: this is an expensive operation. Once the tree hash cache is implement it may be
|
||||
|
||||
@@ -424,7 +424,7 @@ impl<E: EthSpec> HotColdDB<E> {
|
||||
|
||||
for block in blocks {
|
||||
while state.slot < block.slot {
|
||||
per_slot_processing(&mut state, &self.spec)
|
||||
per_slot_processing(&mut state, None, &self.spec)
|
||||
.map_err(HotColdDbError::BlockReplaySlotError)?;
|
||||
}
|
||||
per_block_processing(
|
||||
@@ -438,7 +438,7 @@ impl<E: EthSpec> HotColdDB<E> {
|
||||
}
|
||||
|
||||
while state.slot < target_slot {
|
||||
per_slot_processing(&mut state, &self.spec)
|
||||
per_slot_processing(&mut state, None, &self.spec)
|
||||
.map_err(HotColdDbError::BlockReplaySlotError)?;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user