Section LastAppliedLeCommitIndex.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Proof using.
red. unfold lastApplied_le_commitIndex. intros.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
find_copy_apply_lem_hyp handleAppendEntries_same_lastApplied.
repeat find_rewrite.
find_apply_lem_hyp handleAppendEntries_log_detailed.
intuition; repeat find_rewrite; eauto;
eapply le_trans; eauto; eauto using Max.le_max_l.
Qed.
Proof using.
red. unfold lastApplied_le_commitIndex. intros.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
find_copy_apply_lem_hyp handleAppendEntriesReply_same_lastApplied.
repeat find_rewrite.
find_copy_apply_lem_hyp handleAppendEntriesReply_same_commitIndex.
repeat find_rewrite. eauto.
Qed.
Proof using.
red. unfold lastApplied_le_commitIndex. intros.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
find_copy_apply_lem_hyp handleRequestVote_same_lastApplied.
repeat find_rewrite.
find_copy_apply_lem_hyp handleRequestVote_same_commitIndex.
repeat find_rewrite. eauto.
Qed.
Proof using.
red. unfold lastApplied_le_commitIndex. intros.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
rewrite handleRequestVoteReply_same_lastApplied.
rewrite handleRequestVoteReply_same_commitIndex. eauto.
Qed.
Proof using.
intros.
unfold doLeader, advanceCommitIndex in *.
repeat break_match; simpl in *; find_inversion; auto.
Qed.
Proof using.
induction l; simpl in *; auto.
intros.
specialize (IHl y (max z a)).
forward IHl; eauto. concludes.
forward IHl; [eapply le_trans; eauto; eauto using Max.le_max_l|].
concludes. auto.
Qed.

Lemma advanceCommitIndex_commitIndex :
forall st h,
commitIndex st <= commitIndex (advanceCommitIndex st h).