async def validate_peer_status(chain: BaseBeaconChain, peer_status: Status) -> None: state_machine = chain.get_state_machine() state = chain.get_head_state() config = state_machine.config if peer_status.head_fork_version != state.fork.current_version: raise IrrelevantNetwork( "`fork_version` mismatches: " f"peer_status.head_fork_version={peer_status.head_fork_version}, " f"state.fork.current_version={state.fork.current_version}") # Can not validate the checkpoint with `finalized_epoch` higher than ours if peer_status.finalized_epoch > state.finalized_checkpoint.epoch: return # Edge case where nothing is finalized yet if (peer_status.finalized_epoch == 0 and peer_status.finalized_root == ZERO_ROOT): return finalized_epoch_start_slot = compute_start_slot_at_epoch( peer_status.finalized_epoch, config.SLOTS_PER_EPOCH, ) finalized_root = chain.get_canonical_block_root(finalized_epoch_start_slot) if peer_status.finalized_root != finalized_root: raise IrrelevantNetwork( "`finalized_root` mismatches: " f"peer_status.finalized_root={peer_status.finalized_root.hex()}, " f"peer_status.finalized_epoch={peer_status.finalized_epoch}, " f"our `finalized_root` at the same `finalized_epoch`={finalized_root.hex()}" )
def validate_start_slot(chain: BaseBeaconChain, start_slot: Slot) -> None: config = chain.get_state_machine().config state = chain.get_head_state() finalized_epoch_start_slot = compute_start_slot_at_epoch( epoch=state.finalized_checkpoint.epoch, slots_per_epoch=config.SLOTS_PER_EPOCH, ) if start_slot < finalized_epoch_start_slot: raise ValidationError( f"`start_slot`({start_slot}) lower than our" f" latest finalized slot({finalized_epoch_start_slot})")