Section GhostLogLogMatching.
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 {rlmli : refined_log_matching_lemmas_interface}.
Context {glci : ghost_log_correct_interface}.
Context {lphogli : log_properties_hold_on_ghost_logs_interface}.
Context {tsi : term_sanity_interface}.
Context {aelsi : allEntries_leader_sublog_interface}.
Context {glaei : ghost_log_allEntries_interface}.
Definition ghost_log_entries_match_nw (net : network) : Prop :=
forall p p',
In p (nwPackets net) ->
In p' (nwPackets net) ->
entries_match (fst (pBody p)) (fst (pBody p')).
Definition ghost_log_entries_match (net : network) : Prop :=
ghost_log_entries_match_host net /\
ghost_log_entries_match_nw net.
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.
Definition lifted_entries_contiguous_nw net :=
forall p t n pli plt es ci,
In p (nwPackets net) ->
snd (pBody p) = AppendEntries t n pli plt es ci ->
contiguous_range_exact_lo es pli.
Proof using rlmli rmri.
intros.
assert (entries_contiguous_nw (mgv_deghost net)) by
(apply msg_lift_prop; eauto using entries_contiguous_nw_invariant).
unfold entries_contiguous_nw, lifted_entries_contiguous_nw, mgv_deghost in *;
intros.
simpl in *;
repeat break_match; simpl in *; auto.
match goal with
| H : context [contiguous_range_exact_lo] |- _ =>
specialize (H (@mgv_deghost_packet _ _ ghost_log_params p));
eapply H; simpl in *; eauto
end.
apply in_map_iff. eexists; eauto.
Qed.
Definition lifted_entries_match net :=
forall h h',
entries_match (log (snd (nwState net h))) (log (snd (nwState net h'))).
Proof using rlmli rmri.
intros.
unfold lifted_entries_match; intros.
find_eapply_lem_hyp msg_lift_prop;
[|intros; eapply (entries_match_invariant ltac:(eauto) h h'); eauto].
simpl in *.
repeat break_match; simpl in *; auto.
Qed.
Definition lifted_no_entries_past_current_term_host net :=
forall (h : name) e,
In e (log (snd (nwState net h))) ->
eTerm e <= currentTerm (snd (nwState net h)).

Lemma lifted_no_entries_past_current_term_host_invariant :
forall (net : @network _ raft_msg_refined_multi_params),
msg_refined_raft_intermediate_reachable net ->
lifted_no_entries_past_current_term_host net.