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.

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))).