code: func (n *Node) TransferLeadership(ctx context.Context) error {
  	ctx, cancelTransfer := context.WithTimeout(ctx, n.reqTimeout())
  	defer cancelTransfer()
  
  	n.stopMu.RLock()
  	defer n.stopMu.RUnlock()
  
  	if !n.IsMember() {
  		return ErrNoRaftMember
  	}
  
  	if !n.isLeader() {
  		return ErrLostLeadership
  	}
  
  	transferee, err := n.transport.LongestActive()
  	if err != nil {
  		return errors.Wrap(err, "failed to get longest-active member")
  	}
  	start := time.Now()
  	n.raftNode.TransferLeadership(ctx, n.Config.ID, transferee)
  	ticker := time.NewTicker(n.opts.TickInterval / 10)
  	defer ticker.Stop()
  	var leader uint64
  	for {
  		leader = n.leader()
  		if leader != raft.None && leader != n.Config.ID {
  			break
  		}
  		select {
  		case <-ctx.Done():
  			return ctx.Err()
  		case <-ticker.C:
  		}
  	}
  	log.G(ctx).Infof("raft: transfer leadership %x -> %x finished in %v", n.Config.ID, leader, time.Since(start))
  	return nil
  }
docs: // TransferLeadership attempts to transfer leadership to a different node,
  // and wait for the transfer to happen.