Proof using nisi lmi si rri lhllsi.
red. unfold append_entries_leaderLogs. intros.
subst. simpl in *.
find_apply_hyp_hyp. intuition eauto.
- eapply_prop_hyp In In; break_exists. intuition; eauto.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst. replace gd with (fst (nwState net x)); eauto; repeat find_rewrite; reflexivity.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst. replace gd with (fst (nwState net x)); eauto; repeat find_rewrite; reflexivity.
+ repeat eexists; intuition eauto.
repeat find_higher_order_rewrite.
update_destruct; subst_max; rewrite_update; simpl in *; eauto.
subst. replace gd with (fst (nwState net x)); eauto; repeat find_rewrite; reflexivity.
+ eauto.
- do_in_map. subst.
assert (sorted (log (snd (nwState net h)))) by eauto using lift_logs_sorted.
assert (forall e, In e (log (snd (nwState net h))) -> eIndex e > 0) by eauto using entries_gt_0.
simpl in *.
find_eapply_lem_hyp doLeader_spec; [|eauto|eauto]. intuition.
+ subst.
match goal with
| H : doLeader ?d ?h = _, H' : type ?d = _ |- _ =>
replace d with (snd (nwState net h)) in H by (repeat find_rewrite; reflexivity);
replace d with (snd (nwState net h)) in H' by (repeat find_rewrite; reflexivity)
end.
find_eapply_lem_hyp leaders_have_leaderLogs_strong_invariant; eauto.
exists h.
break_exists_exists. repeat find_rewrite.
eexists; intuition eauto using Prefix_refl; auto.
* simpl in *. repeat find_rewrite.
eapply sorted_findGtIndex_0; eauto.
* simpl in *. repeat find_higher_order_rewrite. rewrite_update. eauto.
+ subst. break_exists. intuition.
find_apply_lem_hyp findAtIndex_elim. intuition. subst.
match goal with
| H : doLeader ?d ?h = _, H' : type ?d = _, H'' : context [log ?d] |- _ =>
replace d with (snd (nwState net h)) in H by (repeat find_rewrite; reflexivity);
replace d with (snd (nwState net h)) in H' by (repeat find_rewrite; reflexivity);
replace d with (snd (nwState net h)) in H'' by (repeat find_rewrite; reflexivity);
replace d with (snd (nwState net h)) by (repeat find_rewrite; reflexivity)
end.
find_copy_apply_lem_hyp lift_log_matching.
unfold log_matching, log_matching_hosts in *. intuition.
match goal with
| H : forall _ _, In _ _ -> _ |- _ =>
specialize (H h x0);
conclude H ltac:(unfold deghost in *;
repeat (break_match; simpl in *);
repeat (simpl in *; find_rewrite);
auto)
end.
find_eapply_lem_hyp leaders_have_leaderLogs_strong_invariant; eauto.
exists h.
break_exists. intuition. exists x1.
repeat (find_rewrite; simpl in *).
do_in_app. intuition.
* find_copy_eapply_lem_hyp findGtIndex_app_in_1; eauto.
break_exists_exists. exists nil.
intuition; simpl in *; auto; eauto using sorted_app_in_1;
[rewrite app_nil_r; auto|].
clear H18.
find_higher_order_rewrite.
rewrite_update.
simpl in *. auto.
* { find_copy_eapply_lem_hyp findGtIndex_app_in_2; eauto.
exists x2. break_exists_exists.
intuition; simpl in *; auto; intuition eauto.
- clear H18. find_higher_order_rewrite. rewrite_update. auto.
- right. left. eexists; intuition; eauto.
match goal with
| |- Prefix_sane ?l _ _ =>
unfold Prefix_sane; destruct l; intuition
end;
try rewrite app_nil_r in *; eauto using findGtIndex_app_eq.
left. intuition. congruence.
}
+ exfalso.
break_exists. intuition.
replace d with (snd (nwState net h)) in * by (repeat find_rewrite; reflexivity).
find_eapply_lem_hyp nextIndex_sanity; eauto. break_exists. congruence.
Qed.

(* Specifications: *)
Lemma append_entries_leaderLogs_init :
refined_raft_net_invariant_init append_entries_leaderLogs.