Proof using rlmli nisi rmri.
red. unfold ghost_log_correct. intros. simpl in *.
match goal with
| H : nwState ?net ?h = (?gd, ?d) |- _ =>
replace gd with (fst (nwState net h)) in * by (rewrite H; reflexivity);
replace d with (snd (nwState net h)) in * by (rewrite H; reflexivity);
clear H
end.
find_apply_hyp_hyp; intuition; eauto.
do_in_map.
subst. simpl in *.
unfold add_ghost_msg in *. do_in_map. subst. simpl in *.
find_eapply_lem_hyp doLeader_replicaMessage; eauto.
break_and.
break_exists. subst.
unfold replicaMessage in *.
simpl in *. find_inversion.
unfold write_ghost_log. simpl.
match goal with
| |- context [pred ?x] =>
remember (pred x) as index
end.
destruct index.
- left. intuition; eauto.
+ break_match; intuition.
find_apply_lem_hyp findAtIndex_elim.
intuition.
find_erewrite_lem doLeader_log; eauto.
enough (0 < eIndex e) by omega.
eapply lifted_entries_contiguous_invariant; eauto.
+ erewrite doLeader_log; eauto.
apply sorted_findGtIndex_0; [|eapply lifted_entries_sorted_invariant; eauto].
intros. eapply lifted_entries_contiguous_invariant; eauto.
- right.
erewrite doLeader_log; eauto.
enough (exists e, findAtIndex (log (snd (nwState net leaderId))) (S index) = Some e) by
(break_exists_name e;
find_copy_apply_lem_hyp findAtIndex_elim; intuition;
auto;
exists e; intuition;
do 2 (unfold raft_data in *; simpl in *);
repeat find_rewrite; auto).
eapply contiguous_findAtIndex;
[eapply lifted_entries_sorted_invariant; eauto|
eapply lifted_entries_contiguous_invariant; eauto|].
intuition.
repeat find_rewrite.
erewrite doLeader_getNextIndex; eauto.
eapply lifted_nextIndex_safety_invariant; eauto.
Qed.

(* Specifications: *)
Lemma ghost_log_correct_do_generic_server :
msg_refined_raft_net_invariant_do_generic_server ghost_log_correct.