Ltac find_eapply_hyp_goal :=
    match goal with
      | H : _ |- _ =>
        eapply H
    end.

(* Specifications: *)
Theorem sorted_append : forall l l', sorted l -> sorted l' -> (forall e e', In e l -> In e' l' -> eIndex e > eIndex e') -> (forall e e', In e l -> In e' l' -> eTerm e >= eTerm e') -> sorted (l ++ l').
Theorem sorted_index_term : forall l e e', eIndex e <= eIndex e' -> sorted l -> In e l -> In e' l -> eTerm e <= eTerm e'.
Lemma handleAppendEntries_logs_sorted : forall net p t n pli plt es ci st' m, raft_intermediate_reachable net -> logs_sorted net -> handleAppendEntries (pDst p) (nwState net (pDst p)) t n pli plt es ci = (st', m) -> pBody p = AppendEntries t n pli plt es ci -> In p (nwPackets net) -> sorted (log st').
Theorem logs_sorted_append_entries : raft_net_invariant_append_entries logs_sorted.
Lemma handleAppendEntriesReply_log : forall h st from t es s st' ps, handleAppendEntriesReply h st from t es s = (st', ps) -> log st' = log st.
Theorem logs_sorted_append_entries_reply : raft_net_invariant_append_entries_reply logs_sorted.
Lemma handleRequestVote_packets : forall h st t candidate lli llt st' m, handleRequestVote h st t candidate lli llt = (st', m) -> ~ is_append_entries m.
Theorem logs_sorted_request_vote : raft_net_invariant_request_vote logs_sorted.
Lemma handleRequestVoteReply_log : forall h st src t vg st', handleRequestVoteReply h st src t vg = st' -> log st' = log st.
Theorem logs_sorted_request_vote_reply : raft_net_invariant_request_vote_reply logs_sorted.
Lemma doLeader_log : forall h st os st' ps, doLeader st h = (os, st', ps) -> log st' = log st.
Lemma doLeader_messages : forall h st os st' ms m t n pli plt entries c, doLeader st h = (os, st', ms) -> sorted (log st) -> In m ms -> snd m = AppendEntries t n pli plt entries c -> subseq entries (log st) /\ (forall e, In e entries -> eIndex e > pli) /\ (forall e, In e entries -> eTerm e >= plt).
Theorem logs_sorted_do_leader : raft_net_invariant_do_leader logs_sorted.
Theorem logs_sorted_do_generic_server : raft_net_invariant_do_generic_server logs_sorted.
Theorem logs_sorted_state_same_packet_subset : raft_net_invariant_state_same_packet_subset logs_sorted.
Theorem logs_sorted_reboot : raft_net_invariant_reboot logs_sorted.
Theorem logs_sorted_invariant : forall net, raft_intermediate_reachable net -> logs_sorted net.