Proof using.
intros.
unfold update_elections_data_appendEntries in *.
repeat break_match; subst; simpl in *; auto.
unfold handleAppendEntries, advanceCurrentTerm in *.
repeat break_match; simpl in *; repeat find_inversion; do_bool; simpl in *; auto;
try (do_in_app; intuition; do_in_map;  repeat find_inversion; subst; simpl in *; auto);
find_eapply_lem_hyp Nat.le_antisymm; eauto.
Qed.

(* Specifications: *)
Lemma update_elections_data_appendEntries_log_allEntries :
forall h st t n pli plt es ci st' h' ps,
handleAppendEntries h (snd st) t n pli plt es ci = (st', ps) ->
(log st' = log (snd st) /\
allEntries (update_elections_data_appendEntries h st t h' pli plt es ci) =
allEntries (fst st))  \/
(allEntries (update_elections_data_appendEntries h st t h' pli plt es ci) =
(map (fun e => (t, e)) es) ++ allEntries (fst st) /\
((currentTerm st' = t /\ log st' = log (snd st) /\ haveNewEntries (snd st) es = false) \/
(currentTerm st' = t /\ currentTerm (snd st) <= t /\ es <> [] /\ pli = 0 /\ log st' = es) \/
(currentTerm st' = t /\ currentTerm (snd st) <= t /\ es <> [] /\ pli <> 0 /\ exists e,
In e (log (snd st)) /\
eIndex e = pli /\
eTerm e = plt) /\
log st' = es ++ (removeAfterIndex (log (snd st)) pli))).