Proof using.
intros. unfold advanceCurrentTerm in *.
break_if; do_bool; intuition.
Qed.

Theorem handleAppendEntries_log_detailed :
forall h st t n pli plt es ci st' ps,
handleAppendEntries h st t n pli plt es ci = (st', ps) ->
(commitIndex st' = commitIndex st /\ log st' = log st) \/
(leaderId st' <> None /\
currentTerm st' = t /\
commitIndex st' = max (commitIndex st) (min ci (maxIndex es)) /\
es <> nil /\
pli = 0 /\ t >= currentTerm st /\ log st' = es /\
(findAtIndex (log st) (maxIndex es) = None \/
exists e,
findAtIndex (log st) (maxIndex es) = Some e /\
eTerm e <> maxTerm es)) \/
(leaderId st' <> None /\
currentTerm st' = t /\
commitIndex st' = max (commitIndex st)
(min ci (maxIndex (es ++ (removeAfterIndex (log st) pli)))) /\
es <> nil /\
exists e,
In e (log st) /\
eIndex e = pli /\
eTerm e = plt) /\
t >= currentTerm st /\
log st' = es ++ (removeAfterIndex (log st) pli) /\
(findAtIndex (log st) (maxIndex es) = None \/
exists e,
findAtIndex (log st) (maxIndex es) = Some e /\
eTerm e <> maxTerm es).