Fix bug in checkpoint manager

This commit is contained in:
Paul Hauner
2020-01-17 16:12:22 +11:00
parent cf72a6cdcc
commit 71947641a6
2 changed files with 16 additions and 6 deletions

View File

@@ -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.

View File

@@ -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(())