becomeCandidate :: Ord nt => Raft nt et rt mt ()
becomeCandidate = do
  debug "becoming candidate"
  role .= Candidate
  term += 1
  rs.writeTermNumber ^=<<. term
  nid <- view (cfg.nodeId)
  setVotedFor $ Just nid
  cYesVotes .= Set.singleton nid -- vote for yourself
  (cPotentialVotes .=) =<< view (cfg.otherNodes)
  resetElectionTimer
  -- this is necessary for a single-node cluster, as we have already won the
  -- election in that case. otherwise we will wait for more votes to check again
  checkElection -- can possibly transition to leader
  r <- use role
  when (r == Candidate) $ fork_ sendAllRequestVotes
becomeCandidate :: Ord nt => Raft nt et rt mt ()
becomeCandidate = do
  debug "becoming candidate"
  role .= Candidate
  term += 1
  rs.writeTermNumber ^=<<. term
  nid <- view (cfg.nodeId)
  setVotedFor $ Just nid
  cYesVotes .= Set.singleton nid -- vote for yourself
  (cPotentialVotes .=) =<< view (cfg.otherNodes)
  resetElectionTimer
  -- this is necessary for a single-node cluster, as we have already won the
  -- election in that case. otherwise we will wait for more votes to check again
  checkElection -- can possibly transition to leader
  r <- use role
  when (r == Candidate) $ fork_ sendAllRequestVotes
becomeCandidate = do
  debug "becoming candidate"
  role .= Candidate
  term += 1
  rs.writeTermNumber ^=<<. term
  nid <- view (cfg.nodeId)
  setVotedFor $ Just nid
  cYesVotes .= Set.singleton nid -- vote for yourself
  (cPotentialVotes .=) =<< view (cfg.otherNodes)
  resetElectionTimer
  -- this is necessary for a single-node cluster, as we have already won the
  -- election in that case. otherwise we will wait for more votes to check again
  checkElection -- can possibly transition to leader
  r <- use role
  when (r == Candidate) $ fork_ sendAllRequestVotes