Ltac prove_in :=
    match goal with
      | [ _ : nwPackets ?net = _,
              _ : In (?p : packet) _ |- _] =>
        assert (In p (nwPackets net)) by (repeat find_rewrite; do_in_app; intuition)
      | [ _ : nwPackets ?net = _,
              _ : pBody ?p = _ |- _] =>
        assert (In p (nwPackets net)) by (repeat find_rewrite; intuition)
    end.

(* Specifications: *)
Lemma contiguous_log_property : log_property (fun l => contiguous_range_exact_lo l 0).
Lemma leaderLogs_contiguous : forall net h t ll, refined_raft_intermediate_reachable net -> In (t, ll) (leaderLogs (fst (nwState net h))) -> contiguous_range_exact_lo ll 0.
Lemma logs_leaderLogs_inductive_appendEntries : refined_raft_net_invariant_append_entries logs_leaderLogs_inductive.
Lemma logs_leaderLogs_inductive_appendEntriesReply : refined_raft_net_invariant_append_entries_reply logs_leaderLogs_inductive.
Lemma logs_leaderLogs_inductive_requestVote : refined_raft_net_invariant_request_vote logs_leaderLogs_inductive.
Lemma logs_leaderLogs_inductive_requestVoteReply : refined_raft_net_invariant_request_vote_reply logs_leaderLogs_inductive.
Lemma logs_leaderLogs_inductive_clientRequest : refined_raft_net_invariant_client_request logs_leaderLogs_inductive.
Lemma logs_leaderLogs_inductive_timeout : refined_raft_net_invariant_timeout logs_leaderLogs_inductive.
Lemma logs_leaderLogs_inductive_doGenericServer : refined_raft_net_invariant_do_generic_server logs_leaderLogs_inductive.
Lemma doLeader_spec : forall st h os st' ms m t n pli plt es ci, doLeader st h = (os, st', ms) -> In m ms -> snd m = AppendEntries t n pli plt es ci -> t = currentTerm st /\ log st' = log st /\ type st = Leader /\ ((pli = 0 /\ plt = 0 /\ es = findGtIndex (log st) 0) \/ ((exists e, findAtIndex (log st) pli = Some e /\ eTerm e = plt) /\ es = findGtIndex (log st) pli) \/ exists h', pred (getNextIndex st h') <> 0 /\ findAtIndex (log st) (pred (getNextIndex st h')) = None).
Lemma logs_leaderLogs_inductive_doLeader : refined_raft_net_invariant_do_leader logs_leaderLogs_inductive.
Lemma logs_leaderLogs_inductive_init : refined_raft_net_invariant_init logs_leaderLogs_inductive.
Lemma logs_leaderLogs_inductive_state_same_packets_subset : refined_raft_net_invariant_state_same_packet_subset logs_leaderLogs_inductive.
Lemma logs_leaderLogs_inductive_reboot : refined_raft_net_invariant_reboot logs_leaderLogs_inductive.
Theorem logs_leaderLogs_inductive_invariant : forall net, refined_raft_intermediate_reachable net -> logs_leaderLogs_inductive net.
Theorem logs_leaderLogs_invariant : forall net, refined_raft_intermediate_reachable net -> logs_leaderLogs net.
Theorem logs_leaderLogs_nw_invariant : forall net, refined_raft_intermediate_reachable net -> logs_leaderLogs_nw net.
Lemma candidate_entries_append_entries_reply : refined_raft_net_invariant_append_entries_reply CandidateEntries.
Lemma update_elections_data_requestVote_cronies_same : forall h h' t lli llt st, cronies (update_elections_data_requestVote h h' t h' lli llt st) = cronies (fst st).
Lemma advanceCurrentTerm_same_or_type_follower : forall st t, advanceCurrentTerm st t = st \/ type (advanceCurrentTerm st t) = Follower.
Lemma handleRV_advanceCurrentTerm_preserves_candidateEntries : forall net h h' t lli llt e, candidateEntries e (nwState net) -> candidateEntries e (update name_eq_dec (nwState net) h (update_elections_data_requestVote h h' t h' lli llt (nwState net h), advanceCurrentTerm (snd (nwState net h)) t)).
Lemma handleRequestVote_preserves_candidateEntries : forall net h h' t lli llt d e m, handleRequestVote h (snd (nwState net h)) t h' lli llt = (d, m) -> candidateEntries e (nwState net) -> candidateEntries e (update name_eq_dec (nwState net) h (update_elections_data_requestVote h h' t h' lli llt (nwState net h), d)).
Lemma handleRequestVote_only_sends_RVR : forall d h h' t lli llt d' m, handleRequestVote h d t h' lli llt = (d', m) -> is_request_vote_reply m.
Lemma candidate_entries_request_vote : refined_raft_net_invariant_request_vote CandidateEntries.
Lemma candidate_entries_request_vote_reply : refined_raft_net_invariant_request_vote_reply CandidateEntries.
Lemma doLeader_in_entries : forall (h : name) d h os d' ms m t li pli plt es ci e, doLeader d h = (os, d', ms) -> snd m = AppendEntries t li pli plt es ci -> In m ms -> In e es -> In e (log d).
Lemma candidate_entries_do_leader : refined_raft_net_invariant_do_leader CandidateEntries.
Lemma doGenericServer_same_type : forall h d os d' ms, doGenericServer h d = (os, d', ms) -> type d' = type d.
Lemma doGenericServer_spec : forall h d os d' ms, doGenericServer h d = (os, d', ms) -> (log d' = log d /\ currentTerm d' = currentTerm d /\ (forall m, In m ms -> ~ is_append_entries (snd m))).
Lemma doGenericServer_preserves_candidateEntries : forall net gd d h os d' ms e, nwState net h = (gd, d) -> doGenericServer h d = (os, d', ms) -> candidateEntries e (nwState net) -> candidateEntries e (update name_eq_dec (nwState net) h (gd, d')).
Lemma candidate_entries_do_generic_server : refined_raft_net_invariant_do_generic_server CandidateEntries.
Lemma candidate_entries_state_same_packet_subset : refined_raft_net_invariant_state_same_packet_subset CandidateEntries.
Lemma reboot_log_same : forall d, log (reboot d) = log d.
Lemma reboot_preservers_candidateEntries : forall net h d gd e, nwState net h = (gd, d) -> candidateEntries e (nwState net) -> candidateEntries e (update name_eq_dec (nwState net) h (gd, reboot d)).
Lemma candidate_entries_reboot : refined_raft_net_invariant_reboot CandidateEntries.
Lemma candidate_entries_init : refined_raft_net_invariant_init CandidateEntries.
Theorem candidate_entries_invariant : forall (net : network), refined_raft_intermediate_reachable net -> CandidateEntries net.