Ltac use_nw_invariant_keep :=
    match goal with
      | [ H : forall _ _ _ _ _ _ _, In _ _ -> Net.pBody _ = _ -> _,
            H' : Net.pBody ?p = AppendEntries _ _ _ _ ?xs _ |- _ ] =>
        copy_apply H H'; clear H; intuition
    end.Ltac use_leader_sublog :=
    match goal with
      | [ H : forall _ _ _ _ _ _  _ _ _, type _ = _ -> In _ _ -> Net.pBody _ = _ -> _,
            H' : Net.pBody ?p = AppendEntries _ _ _ _ ?xs _ |- _ ] =>
        eapply H in H'; clear H; eauto; intuition
    end.Ltac pbody_massage :=
    match goal with
      | H : In ?p _ |- _ =>
        match type of H with
          | context [ nwPackets _ ] => fail 1
          | context [AppendEntries ?t ?lid ?pli ?plt ?e ?lc] =>
            assert (Net.pBody p = AppendEntries t lid pli plt e lc) by reflexivity
        end
    end.

(* Specifications: *)
Lemma client_request_log_matching : raft_net_invariant_client_request log_matching.
Lemma tryToBecomeLeader_spec : forall h d out d' l, tryToBecomeLeader h d = (out, d', l) -> log d' = log d /\ (forall m, In m l -> ~ is_append_entries (snd m)).
Lemma handleTimeout_log_matching : raft_net_invariant_timeout log_matching.
Lemma handleRequestVote_doesn't_send_AE : forall h st t n lli llt d m, handleRequestVote h st t n lli llt = (d, m) -> ~ is_append_entries m.
Lemma handleRequestVote_log_matching : raft_net_invariant_request_vote log_matching.
Lemma handleRequestVoteReply_log_matching : raft_net_invariant_request_vote_reply log_matching.
Lemma log_matching_init : raft_net_invariant_init log_matching.
Lemma log_matching_reboot : raft_net_invariant_reboot log_matching.
Lemma handleAppendEntriesReply_doesn't_send_AE : forall n st src t es b st' l, handleAppendEntriesReply n st src t es b = (st', l) -> forall x, In x l -> ~ is_append_entries (snd x).
Lemma handleAppendEntriesReply_log_matching : raft_net_invariant_append_entries_reply log_matching.
Lemma handleAppendEntries_log_matching_beginning_of_time_entries_match : forall net p t n plt es ci h, log_matching_hosts net -> log_matching_nw net -> logs_sorted_nw net -> uniqueIndices_host_invariant net -> In p (nwPackets net) -> pBody p = AppendEntries t n 0 plt es ci -> pDst p <> h -> entries_match es (log (nwState net h)).
Lemma handleAppendEntries_spec : forall h d t from pli plt entries lci d' m, handleAppendEntries h d t from pli plt entries lci = (d', m) -> ~ is_append_entries m /\ (log d' = log d \/ (pli = 0 /\ log d' = entries) \/ (pli <> 0 /\ (exists e, findAtIndex (log d) pli = Some e /\ eTerm e = plt) /\ log d' = entries ++ (removeAfterIndex (log d) pli))).
Lemma handleAppendEntries_log_matching_middle_of_time_entries_match : forall net p t n pli plt es ci h ple, log_matching_hosts net -> log_matching_nw net -> logs_sorted_host net -> logs_sorted_nw net -> uniqueIndices_host_invariant net -> In p (nwPackets net) -> pBody p = AppendEntries t n pli plt es ci -> findAtIndex (log (nwState net (pDst p))) pli = Some ple -> eTerm ple = plt -> pli <> 0 -> entries_match (es ++ (removeAfterIndex (log (nwState net (pDst p))) pli)) (log (nwState net h)).
Lemma contiguous_range_exact_lo_weaken_exists : forall es lo i, contiguous_range_exact_lo es lo -> lo < i <= maxIndex es -> exists e, eIndex e = i /\ In e es.