Section GhostLogCorrectProof.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Context {rmri : raft_msg_refinement_interface}.
Context {nisi : nextIndex_safety_interface}.
Context {rlmli : refined_log_matching_lemmas_interface}.
Definition lifted_nextIndex_safety net : Prop :=
forall h h',
type (snd (nwState net h)) = Leader ->
pred (getNextIndex (snd (nwState net h)) h') <= maxIndex (log (snd (nwState net h))).
Proof using nisi rmri.
intros.
enough (nextIndex_safety (deghost (mgv_deghost net))) by
(unfold nextIndex_safety, lifted_nextIndex_safety, deghost, mgv_deghost in *;
simpl in *;
repeat break_match; simpl in *; auto).
apply msg_lift_prop_all_the_way; eauto using nextIndex_safety_invariant.
Qed.
Definition lifted_entries_contiguous net :=
forall h,
contiguous_range_exact_lo (log (snd (nwState net h))) 0.
Definition lifted_entries_sorted net :=
forall h,
sorted (log (snd (nwState net h))).
Proof using rlmli rmri.
intros.
enough (entries_contiguous (mgv_deghost net)) by
(unfold entries_contiguous, lifted_entries_contiguous, mgv_deghost in *;
simpl in *;
repeat break_match; simpl in *; auto).
apply msg_lift_prop; eauto using entries_contiguous_invariant.
Qed.
Proof using rlmli rmri.
intros.
enough (entries_sorted (mgv_deghost net)) by
(unfold entries_sorted, lifted_entries_sorted, mgv_deghost in *;
simpl in *;
repeat break_match; simpl in *; auto).
apply msg_lift_prop; eauto using entries_sorted_invariant.
Qed.
Proof using.
red. unfold ghost_log_correct. intros. simpl in *.
find_apply_hyp_hyp; intuition; eauto.
subst. simpl in *.
subst.
find_apply_lem_hyp handleAppendEntries_not_append_entries.
intuition. find_false.
repeat eexists; eauto.
Qed.
Proof using.
red. unfold ghost_log_correct. intros. simpl in *.
find_apply_hyp_hyp; intuition; eauto.
subst. simpl in *.
subst.
find_apply_lem_hyp handleAppendEntriesReply_packets.
subst. simpl in *. intuition.
Qed.
Proof using.
red. unfold ghost_log_correct. intros. simpl in *.
find_apply_hyp_hyp; intuition; eauto.
subst. simpl in *.
subst.
find_apply_lem_hyp handleRequestVote_no_append_entries.
intuition. find_false.
repeat eexists; eauto.
Qed.
Proof using.
red. unfold ghost_log_correct. intros. simpl in *.
find_apply_hyp_hyp; intuition; eauto.
Qed.
Proof using.
unfold doLeader in *.
intros; repeat break_match; find_inversion; simpl in *; intuition.
do_in_map. eauto.
Qed.
Proof using.
intros.
unfold getNextIndex, doLeader, advanceCommitIndex in *.
repeat break_match; find_inversion; simpl in *; auto.
Qed.

Lemma ghost_log_correct_do_leader :
msg_refined_raft_net_invariant_do_leader ghost_log_correct.