Section LeaderLogsLogMatching.
Context {orig_base_params : BaseParams}.
Context {one_node_params : OneNodeParams orig_base_params}.
Context {raft_params : RaftParams orig_base_params}.
Context {rri : raft_refinement_interface}.
Context {lmi : log_matching_interface}.
Context {lltsi : leaderLogs_term_sanity_interface}.
Context {llsi : leaderLogs_sorted_interface}.
Context {si : sorted_interface}.
Context {llsli : leaderLogs_sublog_interface}.
Context {llci : leaderLogs_contiguous_interface}.
Context {taifoi : terms_and_indices_from_one_interface}.
Definition leaderLogs_entries_match_nw (net : network) : Prop :=
forall h llt ll p t src pli plt es ci,
In (llt, ll) (leaderLogs (fst (nwState net h))) ->
In p (nwPackets net) ->
pBody p = AppendEntries t src pli plt es ci ->
(forall e1 e2,
eIndex e1 = eIndex e2 ->
eTerm e1 = eTerm e2 ->
In e1 es ->
In e2 ll ->
(forall e3,
eIndex e3 <= eIndex e1 ->
In e3 es ->
In e3 ll) /\
(pli <> 0 ->
exists e4,
eIndex e4 = pli /\
eTerm e4 = plt /\
In e4 ll)).
Definition leaderLogs_entries_match (net : network) : Prop :=
leaderLogs_entries_match_host net /\
leaderLogs_entries_match_nw net.
Proof using.
unfold refined_raft_net_invariant_init, leaderLogs_entries_match,
leaderLogs_entries_match_host, leaderLogs_entries_match_nw.
simpl.
intuition.
Qed.
Proof using.
unfold entries_match.
intuition; simpl in *; intuition; subst; subst;
try match goal with
| [ H : In _ _ |- _ ] => apply maxTerm_is_max in H; [| solve[auto]]; lia
| [ H : In _ _ |- _ ] => apply maxIndex_is_max in H; [| solve[auto]]; lia
end.
- match goal with
| [ H : _ |- _ ] => solve [eapply H; eauto]
end.
- right. match goal with
| [ H : _ |- _ ] => solve [eapply H; eauto]
end.
Qed.
Proof using.
unfold entries_match.
intuition; simpl in *; intuition; subst; subst;
try solve [
exfalso; try find_apply_hyp_hyp;
match goal with
| [ H : In _ _ |- _ ] => apply maxIndex_is_max in H; [| solve[auto]]; lia
end].
- match goal with
| [ H : _ |- _ ] => solve [eapply H; eauto]
end.
- right. match goal with
| [ H : _ |- _ ] => solve [eapply H; eauto]
end.
Qed.
Proof using.
red.
simpl.
intuition.
Qed.
Proof using si rri.
intros.
pose proof (lift_prop _ logs_sorted_invariant).
find_insterU. conclude_using eauto.
unfold logs_sorted in *. break_and.
unfold logs_sorted_nw in *.
eapply H3.
- unfold deghost. simpl.
apply in_map_iff. eauto.
- simpl. eauto.
Qed.

Lemma lifted_logs_sorted_host :
forall net h ,
refined_raft_intermediate_reachable net ->
sorted (log (snd (nwState net h))).