Section inner.
Variable client : clientId.
Variable id : nat.
Fixpoint client_id_in l :=
match l with
| [] => false
| e :: l' =>
if (andb (if clientId_eq_dec (eClient e) client then true else false)
(eId e =? id)) then
true
else
client_id_in l'
end.
Proof using.
intros. unfold in_applied_entries.
induction (applied_entries (nwState net)); simpl in *; try congruence.
break_if; break_if; do_bool; intuition; try congruence; do_bool; eauto;
break_exists_exists; intuition.
Qed.
Proof using.
intros. unfold in_applied_entries.
induction (applied_entries (nwState net)); simpl in *; try congruence; intuition.
- break_exists; intuition.
- break_if; try congruence.
do_bool.
break_exists; break_if; try congruence; intuition; do_bool; subst; eauto.
Qed.
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 lia.
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 lia. 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.
Proof using lmi si.
intros.
find_copy_apply_lem_hyp logs_sorted_invariant.
pose proof log_matching_invariant.
eapply_prop_hyp raft_intermediate_reachable raft_intermediate_reachable.
unfold log_matching, log_matching_hosts, logs_sorted in *.
intuition.
match goal with
| H : forall _ _, _ <= _ <= _ -> _ |- _ =>
specialize (H h i);
conclude H ltac:(intuition; find_apply_lem_hyp maxIndex_is_max; eauto; lia)
end.
break_exists_exists. intuition. apply findAtIndex_intro; eauto using sorted_uniqueIndices.
Qed.
Proof using lmi.
intros.
find_apply_lem_hyp maxIndex_non_empty.
break_exists; intuition; find_rewrite.
find_apply_lem_hyp log_matching_invariant.
unfold log_matching, log_matching_nw in *.
intuition. destruct (pBody p) eqn:?; simpl in *; try congruence.
find_apply_hyp_hyp. intuition. find_inversion.
find_apply_hyp_hyp. lia.
Qed.
Proof using lmi.
intros.
find_apply_lem_hyp log_matching_invariant.
unfold log_matching, log_matching_hosts in *.
intuition.
unfold contiguous_range_exact_lo.
intuition eauto.
find_apply_hyp_hyp. intuition.
Qed.
Proof using lmi.
intros.
find_apply_lem_hyp log_matching_invariant.
unfold log_matching, log_matching_nw in *.
intuition. destruct (pBody p) eqn:?; simpl in *; try congruence.
find_inversion.
find_apply_hyp_hyp. intuition.
find_apply_hyp_hyp. lia.
Qed.
Proof using lmi.
intros.
find_apply_lem_hyp log_matching_invariant.
unfold log_matching, log_matching_nw in *.
intuition. destruct (pBody p) eqn:?; simpl in *; try congruence.
find_inversion.
find_apply_hyp_hyp. intuition.
Qed.

Lemma sorted_app :
forall l l',
sorted (l ++ l') ->
sorted l.