Proof using lacimi si.
intros.
unfold doGenericServer in *. break_let. find_inversion.
find_copy_apply_lem_hyp logs_sorted_invariant. unfold logs_sorted, logs_sorted_host in *.
intuition.
use_applyEntries_spec. subst. simpl in *. unfold raft_data in *.
simpl in *.
break_if; [|rewrite applied_entries_safe_update; simpl in *; eauto;
exists nil; simpl in *; intuition].
do_bool.
match goal with
| |- context [update _ ?sigma ?h ?st] => pose proof applied_entries_update sigma h st
end.
simpl in *.
assert (commitIndex (sigma h) >= lastApplied (sigma h)) by omega.
concludes. intuition; [find_rewrite; exists nil; simpl in *; intuition|].
pose proof applied_entries_cases sigma.
intuition; repeat find_rewrite; eauto;
[eexists; intuition; eauto;
find_apply_lem_hyp in_rev;
find_copy_apply_lem_hyp removeAfterIndex_In_le; eauto;
find_apply_lem_hyp removeAfterIndex_in; eexists; intuition; eauto|].
match goal with | H : exists _, _ |- _ => destruct H as [h'] end.
repeat find_rewrite.
find_apply_lem_hyp argmax_elim. intuition.
match goal with
| H : forall _: name, _ |- _ =>
specialize (H h'); conclude H ltac:(eauto using all_fin_all)
end.
rewrite_update. simpl in *.
update_destruct; subst; rewrite_update; simpl in *.
+ match goal with
| h : name |- _ =>
pose proof removeAfterIndex_partition (removeAfterIndex (log (sigma h)) (commitIndex (sigma h))) (lastApplied (sigma h))
end.
find_apply_lem_hyp rev_exists.
break_exists_exists.
repeat find_rewrite.
rewrite <- removeAfterIndex_le by omega. intuition.
find_eapply_lem_hyp app_in_2; eauto.
find_apply_lem_hyp In_rev.
find_copy_apply_lem_hyp removeAfterIndex_in.
find_apply_lem_hyp removeAfterIndex_In_le; eauto.
+ match goal with
| _ : ?h <> ?h' |- context [ removeAfterIndex ?l (commitIndex (?sigma ?h)) ] =>
pose proof removeAfterIndex_partition (removeAfterIndex l (commitIndex (sigma h)))
(lastApplied (sigma h'))
end.
find_apply_lem_hyp rev_exists.
break_exists_exists.
repeat match goal with | H : applied_entries _ = _ |- _ => clear H end.
find_rewrite.
erewrite <- removeAfterIndex_le; eauto.
intuition.
* f_equal. f_equal.
find_copy_apply_lem_hyp lastApplied_commitIndex_match_invariant.
eapply removeAfterIndex_same_sufficient; eauto;
intros;
eapply_prop_hyp lastApplied_commitIndex_match le; intuition eauto.
* find_eapply_lem_hyp app_in_2; eauto.
find_apply_lem_hyp In_rev.
find_copy_apply_lem_hyp removeAfterIndex_in.
find_apply_lem_hyp removeAfterIndex_In_le; eauto.
Qed.

Lemma findAtIndex_max_thing :
forall net h e i,
raft_intermediate_reachable net ->
In e (log (nwState net h)) ->
eIndex e > i ->
1 <= i ->
exists e',
findAtIndex (log (nwState net h)) i = Some e'.