   end
 
   defmodule State do
-    @leader_election_interval_ms 4000
+    @leader_election_interval_ms 1000
+    @append_entries_interval_ms 500
 
     defstruct [
       :role, :leader, :term, :log, :commit_log, :commit_idx,


      state =
        if vote_granted do
          %{state | voted_for: rpc.candidate}
        else
          state
        end

    end

    def handle_rpc(state, member, %RPC.ReplyRequestVote{} = rpc) do
      Logger.info(">> #{member.name} voted #{rpc.granted}")

      state =
        case state.role do
          # Vote only matters if we're still a candidate
          :candidate ->
            votes =
              if rpc.granted do
                MapSet.put(state.leader_state.votes, member.name)
              else
                state.leader_state.votes
              end

            vote_count = MapSet.size(votes)
            majority_votes = div(Map.size(Pontoon.Membership.list()), 2) + 1

            {role, term} =
                if vote_count >= majority_votes do
                  Logger.info("Received majority #{vote_count}/#{majority_votes}! Seizing power")
                  {:leader, state.term + 1}
                else
                  Logger.info("election not over yet, #{vote_count}/#{majority_votes}")
                  {:candidate, state.term}
                end

            %{state |
              role: role,
              term: term,
              leader_state: %{ state.leader_state | votes: votes}}


          _else ->
            state
        end

      {nil, state}
