mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 08:52:54 +00:00
Fix bug in checkpoint manager
This commit is contained in:
@@ -134,7 +134,7 @@ impl<T: BeaconChainTypes> ForkChoice<T> {
|
|||||||
|
|
||||||
self.checkpoint_manager
|
self.checkpoint_manager
|
||||||
.write()
|
.write()
|
||||||
.process_state(state, chain, &self.backend)?;
|
.process_state(block_root, state, chain, &self.backend)?;
|
||||||
self.checkpoint_manager.write().update(chain)?;
|
self.checkpoint_manager.write().update(chain)?;
|
||||||
|
|
||||||
// Note: we never count the block as a latest message, only attestations.
|
// Note: we never count the block as a latest message, only attestations.
|
||||||
|
|||||||
@@ -18,9 +18,17 @@ struct BalancesCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BalancesCache {
|
impl BalancesCache {
|
||||||
pub fn process_state<E: EthSpec>(&mut self, state: &BeaconState<E>) -> Result<(), Error> {
|
pub fn process_state<E: EthSpec>(
|
||||||
|
&mut self,
|
||||||
|
block_root: Hash256,
|
||||||
|
state: &BeaconState<E>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
let epoch_boundary_slot = state.current_epoch().start_slot(E::slots_per_epoch());
|
let epoch_boundary_slot = state.current_epoch().start_slot(E::slots_per_epoch());
|
||||||
let epoch_boundary_root = *state.get_block_root(epoch_boundary_slot)?;
|
let epoch_boundary_root = if epoch_boundary_slot == state.slot {
|
||||||
|
block_root
|
||||||
|
} else {
|
||||||
|
*state.get_block_root(epoch_boundary_slot)?
|
||||||
|
};
|
||||||
|
|
||||||
if self.position(epoch_boundary_root).is_none() {
|
if self.position(epoch_boundary_root).is_none() {
|
||||||
let item = CacheItem {
|
let item = CacheItem {
|
||||||
@@ -129,12 +137,14 @@ impl CheckpointManager {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks the given `state` to see if it contains a `current_justified_checkpoint` that is
|
/// Checks the given `state` (must correspond to the given `block_root`) to see if it contains
|
||||||
/// better than `self.best_justified_checkpoint`. If so, the value is updated.
|
/// a `current_justified_checkpoint` that is better than `self.best_justified_checkpoint`. If
|
||||||
|
/// so, the value is updated.
|
||||||
///
|
///
|
||||||
/// Note: this does not update `self.justified_checkpoint`.
|
/// Note: this does not update `self.justified_checkpoint`.
|
||||||
pub fn process_state<T: BeaconChainTypes>(
|
pub fn process_state<T: BeaconChainTypes>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
block_root: Hash256,
|
||||||
state: &BeaconState<T::EthSpec>,
|
state: &BeaconState<T::EthSpec>,
|
||||||
chain: &BeaconChain<T>,
|
chain: &BeaconChain<T>,
|
||||||
proto_array: &ProtoArrayForkChoice,
|
proto_array: &ProtoArrayForkChoice,
|
||||||
@@ -189,7 +199,7 @@ impl CheckpointManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the state's balances to the balances cache to avoid a state read later.
|
// Add the state's balances to the balances cache to avoid a state read later.
|
||||||
self.balances_cache.process_state(state)?;
|
self.balances_cache.process_state(block_root, state)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user