code: func (s *Store) invalidateServiceLeader(service string) {
  	// Retrieve service config.
  	c := s.data.Services[service]
  
  	// Ignore if there is no config or the leader is manually elected.
  	if c == nil || c.LeaderType == discoverd.LeaderTypeManual {
  		return
  	}
  
  	// Retrieve current leader ID.
  	prevLeaderID := s.data.Leaders[service]
  
  	// Find the oldest, non-expired instance.
  	var leader *discoverd.Instance
  	for _, inst := range s.data.Instances[service] {
  		if leader == nil || inst.Index < leader.Index {
  			leader = inst
  		}
  	}
  
  	// Retrieve the leader ID.
  	var leaderID string
  	if leader != nil {
  		leaderID = leader.ID
  	}
  
  	// Set leader.
  	s.data.Leaders[service] = leaderID
  
  	// Broadcast event.
  	if prevLeaderID != leaderID {
  		var inst *discoverd.Instance
  		if s.data.Instances[service] != nil {
  			inst = s.data.Instances[service][leaderID]
  		}
  
  		s.broadcast(&discoverd.Event{
  			Service:  service,
  			Kind:     discoverd.EventKindLeader,
  			Instance: inst,
  		})
  	}
  }
docs: // invalidateServiceLeader updates the current leader of service.