Section LogsLeaderLogs.
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 {llsi : leaderLogs_sorted_interface}.
Context {rlmli : refined_log_matching_lemmas_interface}.
Context {llci : leaderLogs_contiguous_interface}.
Context {lllmi : leaderLogs_entries_match_interface}.
Context {lhllsi : leaders_have_leaderLogs_strong_interface}.
Context {nisi : nextIndex_safety_interface}.
Context {si : sorted_interface}.
Context {lpholli : log_properties_hold_on_leader_logs_interface}.
Definition weak_sanity pli ll ll' :=
pli = 0 ->
(exists e, eIndex e = 0 /\ In e ll) \/
ll = ll'.
Definition logs_leaderLogs_nw_weak net :=
forall p t n pli plt es ci e,
In p (nwPackets net) ->
pBody p = AppendEntries t n pli plt es ci ->
In e es ->
exists leader ll es' ll',
In (eTerm e, ll) (leaderLogs (fst (nwState net leader))) /\
Prefix ll' ll /\
removeAfterIndex es (eIndex e) = es' ++ ll' /\
(forall e', In e' es' -> eTerm e' = eTerm e) /\
weak_sanity pli ll ll'.
Proof using.
intros. unfold logs_leaderLogs_nw, logs_leaderLogs_nw_weak, weak_sanity in *.
intros.
eapply_prop_hyp In In; eauto.
break_exists_exists; intuition; subst; try lia.
break_exists; intuition; eauto.
Qed.
Definition logs_leaderLogs_inductive net :=
logs_leaderLogs net /\
logs_leaderLogs_nw net.
Proof using si rri.
intros.
eapply lift_prop; eauto using logs_sorted_invariant.
Qed.

Theorem lift_logs_sorted :
forall net h,
refined_raft_intermediate_reachable net ->
sorted (log (snd (nwState net h))).