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.

Lemma fold_left_max :
forall l y z,
(forall x, In x l ->
y <= x) ->
y <= z ->
y <= fold_left max l z.