Section OutputGreatestId.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Context {lmi : log_matching_interface}.
Context {si : sorted_interface}.
Context {aemi : applied_entries_monotonic_interface}.
Context {smsi : state_machine_safety_interface}.
Context {misi : max_index_sanity_interface}.
Context {smci : state_machine_correct_interface}.
Context {lacimi : lastApplied_commitIndex_match_interface}.
Proof using.
intros. unfold key_in_output_trace in *.
break_exists_exists.
intuition. do_in_app; intuition.
exfalso. eauto.
Qed.
Proof using.
intros.
unfold key_in_output_list in *.
break_exists; do_in_app; intuition eauto.
Qed.
Proof using.
intuition.
unfold key_in_output_list in *.
break_exists; intuition.
Qed.
Proof using.
intros. unfold doLeader, advanceCommitIndex in *.
repeat break_match; find_inversion; intuition;
find_apply_lem_hyp key_in_output_list_empty; auto.
Qed.
Proof using.
intros. unfold handleInput, handleTimeout, handleClientRequest, tryToBecomeLeader in *.
repeat break_match; find_inversion; intuition eauto using key_in_output_list_empty;
unfold key_in_output_list in *; break_exists; simpl in *; intuition; congruence.
Qed.
Proof using.
intros. unfold has_key. break_match; subst; simpl in *.
break_if; repeat (do_bool; intuition).
Qed.
Proof using.
intros. unfold has_key in *. break_match.
simpl in *. subst.
break_if; repeat (do_bool; intuition); try congruence.
Qed.
Proof using.
induction l; intros; simpl in *; intuition.
- find_inversion. simpl in *. intuition.
- unfold cacheApplyEntry, applyEntry in *.
repeat break_match; repeat find_inversion; simpl in *; intuition; eauto;
try solve
[find_inversion; find_rewrite; find_inversion; do_bool; lia];
try solve [find_inversion; repeat find_rewrite; congruence].
+ do_bool. destruct (clientId_eq_dec (eClient a) client).
* subst. find_rewrite. find_inversion.
eapply IHl; [eapply lt_le_trans; eauto|idtac|idtac|]; eauto.
unfold getLastId.
simpl. eauto using get_set_same.
* eapply IHl; eauto.
unfold getLastId in *.
simpl. rewrite get_set_diff; eauto.
+ do_bool. destruct (clientId_eq_dec (eClient a) client).
* repeat find_rewrite. congruence.
* eapply IHl; eauto.
unfold getLastId in *.
simpl. rewrite get_set_diff; eauto.
+ do_bool. destruct (clientId_eq_dec (eClient a) client).
* repeat find_rewrite. find_inversion.
eapply IHl; [eapply lt_le_trans; eauto|idtac|idtac|]; eauto.
unfold getLastId.
simpl. eauto using get_set_same.
* eapply IHl; eauto.
unfold getLastId in *.
simpl. rewrite get_set_diff; eauto.
+ do_bool. destruct (clientId_eq_dec (eClient a) client).
* repeat find_rewrite. congruence.
* eapply IHl; eauto.
unfold getLastId in *.
simpl. rewrite get_set_diff; eauto.
Qed.

Lemma applyEntries_before :
forall l h st os st' o client id id',
id < id' ->
applyEntries h st l = (os, st') ->
In (ClientResponse client id o) os ->
before_func (has_key client id) (has_key client id') l.