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.
Proof using.
intros. unfold advanceCommitIndex. simpl in *.
apply fold_left_max; auto.
intros.
do_in_map. subst.
find_apply_lem_hyp filter_In.
repeat (intuition; do_bool).
Qed.
Proof using.
intros.
unfold doLeader in *.
repeat break_match; tuple_inversion; auto; eauto using advanceCommitIndex_commitIndex.
eapply le_trans; [eapply advanceCommitIndex_commitIndex with (h := h0)|]; eauto.
Qed.
Proof using.
red. unfold lastApplied_le_commitIndex. intros.
subst.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
find_copy_apply_lem_hyp doLeader_same_lastApplied.
find_copy_apply_lem_hyp doLeader_same_commitIndex.
repeat find_rewrite. eapply le_trans; [|eauto]; eauto.
Qed.
Proof using.
intros. unfold doGenericServer in *. break_let. find_inversion.
simpl in *.
break_if; simpl in *; do_bool; auto.
- use_applyEntries_spec. subst. simpl in *.
eauto using Max.le_max_r.
- use_applyEntries_spec. subst. simpl in *.
eauto using Max.le_max_l.
Qed.
Proof using.
red. unfold lastApplied_le_commitIndex. intros.
subst.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
find_copy_apply_lem_hyp doGenericServer_commitIndex.
find_copy_apply_lem_hyp doGenericServer_lastApplied.
repeat find_rewrite.
erewrite Max.max_r in *; eauto.
Qed.
Proof using.
red. unfold lastApplied_le_commitIndex. intros.
subst.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
find_copy_apply_lem_hyp handleClientRequest_commitIndex.
find_copy_apply_lem_hyp handleClientRequest_lastApplied.
repeat find_rewrite. eauto.
Qed.
Proof using.
red. unfold lastApplied_le_commitIndex. intros.
subst.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
find_copy_apply_lem_hyp handleTimeout_commitIndex.
find_copy_apply_lem_hyp handleTimeout_lastApplied.
repeat find_rewrite. eauto.
Qed.
Proof using.
red. unfold lastApplied_le_commitIndex. intros.
subst.
simpl in *. repeat find_higher_order_rewrite.
destruct_update; simpl in *; eauto.
Qed.
Proof using.
red. unfold lastApplied_le_commitIndex. intros.
subst.
simpl in *. repeat find_reverse_higher_order_rewrite. auto.
Qed.
Proof using.
red. unfold lastApplied_le_commitIndex. intros.
simpl in *. auto.
Qed.

Theorem lastApplied_le_commitIndex_invariant :
forall net,
raft_intermediate_reachable net ->
lastApplied_le_commitIndex net.